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

Cannot update a component (LayerContextProvider) while rendering a different component (Frame) #668

Open
addlistener opened this issue Jul 10, 2024 · 1 comment

Comments

@addlistener
Copy link

addlistener commented Jul 10, 2024

Describe the bug

next-dev.js:20 Warning: Cannot update a component (`LayerContextProvider`) while rendering a different component (`Frame`). To locate the bad setState() call inside `Frame`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
    at Frame (webpack-internal:///../../packages/core/dist/esm/index.js:510:18)
    at div
    at Content (webpack-internal:///../../node_modules/react-frame-component/lib/Content.js:30:5)
    at iframe
    at Frame (webpack-internal:///../../node_modules/react-frame-component/lib/Frame.js:46:5)
    at div
    at div
    at div
    at Viewport (webpack-internal:///./components/editor/Viewport/index.tsx:26:11)
    at Events (webpack-internal:///../../packages/core/dist/esm/index.js:2345:19)
    at Editor (webpack-internal:///../../packages/core/dist/esm/index.js:2436:19)

To Reproduce
Adding a react-frame-component just ouside the <Frame />

      <Viewport>
        <ReactFrameComponent>
          <Frame>
            ...

Running yarn start in example/landing

I briefly checked the code and found that

const isLoaded = useRef(false);
if (!isLoaded.current) {
const initialData = data || json;
if (initialData) {
actions.history.ignore().deserialize(initialData);
} else if (children) {
const rootNode = React.Children.only(children) as React.ReactElement;
const node = query.parseReactElement(rootNode).toNodeTree((node, jsx) => {
if (jsx === rootNode) {
node.id = ROOT_NODE;
}
return node;
});
actions.history.ignore().addNodeTree(node);
}
isLoaded.current = true;
}

these lines should be updated in a useEffect instead of render?

Expected behavior
No warning

Your environment

Software Version(s)
craft.js 46eb68e
React 18.2.0
TypeScript typescript@4.9.5
Browser Version 126.0.6478.127 (Official Build) (x86_64)
npm/Yarn 3.6.3
Operating System Darwin 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:42:42 PDT 2023; root:xnu-10002.1.13~1/RELEASE_X86_64 x86_64
@Traveller23
Copy link
Contributor

Traveller23 commented Aug 12, 2024

The changes in feat: SSR support also led to another problem being exposed:

#693

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants