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

returning undefined in usePlasmicQueryData causes react component to rerender infinitely #75

Open
lucasmerlin opened this issue Mar 27, 2023 · 0 comments

Comments

@lucasmerlin
Copy link

Simple reproduction:

  1. Create a new plasmic nextjs project
  2. Add simple Component that returns undefined in usePlasmicQueryData:
export const QueryComponent = ({children}: {
  children: ReactNode
}) => {
  console.log("I'm being rendered")
  const data = usePlasmicQueryData("query", () => {
    // comment this line and the infinite loop goes away
    return undefined;

    return {
      data: "test",
    }
  })
  
  console.log("Data: ", data)
  return <DataProvider data={data}>
    {children}
  </DataProvider>
}
  1. Use the component in extractPlasmicQueryData:
  const queryCache = await extractPlasmicQueryData(
    <PlasmicRootProvider
      loader={PLASMIC}
      prefetchedData={plasmicData}
      pageParams={pageMeta.params}
    >
      <QueryComponent>
        <PlasmicComponent component={pageMeta.displayName} />
      </QueryComponent>
    </PlasmicRootProvider>
  );
  1. Start dev server and go to localhost:3000
  2. The dev server goes to 100% cpu usage and keeps logging
I'm being rendered
I'm being rendered
I'm being rendered

I also created a reproduction repo: https://github.com/lucasmerlin/plasmic-loop-debug

Expected behaviour

I would expect the usePlasmicQueryData just to return undefined or to throw an error maybe, but no infinite loop.

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

1 participant