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: dev mode ui state stuck in theme manager #160

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/internal/components/ThemeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { useCallback, useEffect, useState } from "react";
import { InitialHistory, Config, Data } from "@measured/puck";
import {
InitialHistory,
Config,
Data,
History,
AppState,
} from "@measured/puck";
import { TemplateMetadata } from "../types/templateMetadata.ts";
import { useThemeLocalStorage } from "../hooks/theme/useLocalStorage.ts";
import { DevLogger } from "../../utils/devLogger.ts";
Expand Down Expand Up @@ -71,13 +77,18 @@ export const ThemeEditor = (props: ThemeEditorProps) => {

// use layout from localStorage when in dev mode
if (templateMetadata.isDevMode && !!localHistoryArray) {
const localHistories = JSON.parse(localHistoryArray) as History[];
const localHistories = JSON.parse(
localHistoryArray
) as History<AppState>[];
const localHistoryIndex = localHistories.length - 1;
if (localHistoryIndex >= 0) {
devLogger.log("Theme Dev Mode - Using layout data from local storage");
setPuckInitialHistory({
// @ts-expect-error https://github.com/measuredco/puck/issues/673
histories: localHistories,
histories: localHistories.map((h) => {
// strip ui state
benlife5 marked this conversation as resolved.
Show resolved Hide resolved
return { id: h.id, state: { data: { ...h.state.data } } };
}),
index: localHistoryIndex,
appendData: false,
});
Expand Down