Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initialHistory not reflected in appState #562

Closed
wants to merge 14 commits into from
3 changes: 2 additions & 1 deletion packages/core/components/Puck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ export function Puck<UserConfig extends Config = Config>({
const { resolveData, componentState } = useResolvedData(
appState,
config,
dispatch
dispatch,
historyStore.histories[historyStore.index]?.data
);

const [menuOpen, setMenuOpen] = useState(false);
Expand Down
19 changes: 18 additions & 1 deletion packages/core/lib/use-resolved-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { resolveRootData } from "./resolve-root-data";
export const useResolvedData = (
appState: AppState,
config: Config,
dispatch: Dispatch<PuckAction>
dispatch: Dispatch<PuckAction>,
historyState?: AppState
) => {
const [{ resolverKey, newAppState }, setResolverState] = useState({
resolverKey: 0,
Expand Down Expand Up @@ -80,6 +81,22 @@ export const useResolvedData = (

const promises: Promise<void>[] = [];

// Resolve the initialHistory with the appState
if (historyState) {
promises.push(
(async () => {
dispatch({
type: "set",
state: (prev) => ({
...prev,
...historyState,
}),
recordHistory: resolverKey > 0,
});
})()
);
}

promises.push(
(async () => {
setComponentLoading("puck-root", true, 50);
Expand Down
Loading