bvaughn / react-resizable-panels

https://react-resizable-panels.vercel.app/
MIT License
3.58k stars 124 forks source link

Following docs for "persistent layouts with SSR" doesnt work #359

Closed laneme closed 1 month ago

laneme commented 1 month ago

Quick look at this issue seem to be related to the onLayout callback. onLayout apparently fires before the defaultSize is set, resetting the document.cookie value. So the flickerring persist.

To reproduce, visit https://ui.shadcn.com/examples/mail, see the cookie is reset after page refresh. The reset doesnt happen if you remove the onLayout.

You can view the code from here. apps/www/app/(app)/examples/mail/components/mail.tsx

bvaughn commented 1 month ago

This issue hasn't impacted me or any of my projects using the library. If you'd like to submit a proposed fix, I'll review it.

laneme commented 1 month ago

My bad. My assumptions were wrong about the onLayout behavior.

The reason this happened (on my version) was because I only set defaultValue for the first panel, out of two panels. Which felt intuitive for me.

And the issue on shadcn's version is probably different, even though that looked identical to mine.

I pushed a pr to update the docs with a note at the bottom.

bvaughn commented 1 month ago

Thanks for the PR and for the follow up. Glad you go this sorted out.