Error using useHydrateAtoms with Next.js parallel-routes #2526
-
I am using Next.js parallel-routes, with two sibling components rendered in a common layout.
export const ComponentA = ({ dataFromServer }) => {
useHydrateAtoms([[dataAtom, dataFromServer]], {
dangerouslyForceHydrate: true
});
return null;
};
export const ComponentB = () => {
const data = useAtomValue(dataAtom);
return <div>{JSON.stringify(data)}</div>;
}; The The initial render works fine, but if I pass a new search param (which passes different
This also happens if instead of parallel-routes and siblings, I make <ComponentA dataFromServer={data}>
<ComponentB /> // <--- Notice I am not prop drilling, but instead am using useAtomValue
</ComponentA /> Is this a bug or expected behavior that isn't documented (or perhaps I missed the documentation)? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Thanks for the simpler reproduction. |
Beta Was this translation helpful? Give feedback.
-
Okay, then I think this is something not possible to work around on our end.
It means, ComponentB renders first and then ComponentA. |
Beta Was this translation helpful? Give feedback.
Okay, then I think this is something not possible to work around on our end.
It means, ComponentB renders first and then ComponentA.
So, it's an expected behavior, and the workaround is
<ComponentB dataFromServer={data} />
.