Skip to content

Commit

Permalink
refactor: don't render frame override if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Aug 31, 2024
1 parent d01eed4 commit 460b3a5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/core/components/Puck/components/Preview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DropZone } from "../../../DropZone";
import { rootDroppableId } from "../../../../lib/root-droppable-id";
import { ReactNode, useCallback, useMemo, useRef } from "react";
import { ReactNode, useCallback, useMemo } from "react";
import { useAppContext } from "../../context";
import AutoFrame, { autoFrameContext } from "../../../AutoFrame";
import styles from "./styles.module.css";
Expand Down Expand Up @@ -30,7 +30,7 @@ export const Preview = ({ id = "puck-preview" }: { id?: string }) => {
[config.root]
);

const Frame = useMemo(() => overrides.iframe || "div", [overrides]);
const Frame = useMemo(() => overrides.iframe, [overrides]);

// DEPRECATED
const rootProps = state.data.root.props || state.data.root;
Expand All @@ -54,13 +54,17 @@ export const Preview = ({ id = "puck-preview" }: { id?: string }) => {
>
<autoFrameContext.Consumer>
{({ document }) => {
return (
<Frame document={document}>
<Page dispatch={dispatch} state={state} {...rootProps}>
<DropZone zone={rootDroppableId} />
</Page>
</Frame>
const inner = (
<Page dispatch={dispatch} state={state} {...rootProps}>
<DropZone zone={rootDroppableId} />
</Page>
);

if (Frame) {
return <Frame document={document}>{inner}</Frame>;
}

return inner;
}}
</autoFrameContext.Consumer>
</AutoFrame>
Expand Down

0 comments on commit 460b3a5

Please sign in to comment.