Skip to content

Commit

Permalink
fix: fix defaultProps for root
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Apr 19, 2024
1 parent 9df6633 commit 9a1cc7c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions apps/demo/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export type UserConfig = Config<
// We avoid the name config as next gets confused
export const conf: UserConfig = {
root: {
defaultProps: {
title: "My Page",
},
render: Root,
},
categories: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/components/MenuBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getClassName = getClassNameFactory("MenuBar", styles);

export const MenuBar = ({
appState,
data = { content: [], root: { props: { title: "" } } },
data = { content: [], root: {} },
dispatch,
menuOpen = false,
onPublish,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/components/Puck/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { IframeConfig } from "../../types/IframeConfig";
import { UAParser } from "ua-parser-js";

export const defaultAppState: AppState = {
data: { content: [], root: { props: { title: "" } } },
data: { content: [], root: { props: {} } },
ui: {
leftSideBarVisible: true,
rightSideBarVisible: true,
Expand Down
15 changes: 13 additions & 2 deletions packages/core/components/Puck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const getClassName = getClassNameFactory("Puck", styles);
export function Puck<UserConfig extends Config = Config>({
children,
config,
data: initialData = { content: [], root: { props: { title: "" } } },
data: initialData = { content: [], root: {} },
ui: initialUi,
onChange,
onPublish,
Expand Down Expand Up @@ -146,9 +146,20 @@ export function Puck<UserConfig extends Config = Config>({
}
}

// DEPRECATED
const rootProps = initialData.root.props || initialData.root;

const defaultedRootProps = {
...config.root?.defaultProps,
...rootProps,
};

return {
...defaultAppState,
data: initialData,
data: {
...initialData,
root: defaultedRootProps,
},
ui: {
...initial,
...clientUiState,
Expand Down

0 comments on commit 9a1cc7c

Please sign in to comment.