Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/builder-no-save-on-open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frontlit/page-builder": patch
---

Opening a page in the builder no longer calls `onChange`; it fires only after the user changes something.
13 changes: 12 additions & 1 deletion packages/page-builder/src/builder/page-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function PageBuilder({
const [layout, setLayout] = useState<WidgetInstance[]>(() =>
initialLayout
? // Rich text saved before the page text profile is cut down to it, so
// the builder's first save stores a layout that validates.
// the next save stores a layout that validates.
ensureRequiredSharedWidgets(
withDefaultSettings(
initialLayout.map((block) => ({
Expand Down Expand Up @@ -139,7 +139,18 @@ export function PageBuilder({
[],
);

// Opening the page isn't an edit: only report state the user changed.
const openedWith = useRef({ layout, theme, seo, customThemes });
useEffect(() => {
const opened = openedWith.current;
if (
layout === opened.layout &&
theme === opened.theme &&
seo === opened.seo &&
customThemes === opened.customThemes
) {
return;
}
emitChange({ layout, theme, seo, customThemes });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [layout, theme, seo, customThemes]);
Expand Down
Loading