-
-
Notifications
You must be signed in to change notification settings - Fork 195
SSR Persistence Script #521
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
base: main
Are you sure you want to change the base?
Conversation
…utes and improved state handling
|
@isBatak is attempting to deploy a commit to the Brian Vaughn's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
This seems like a promising idea, but it also seems like it will require a lot of testing and validating to reduce causing regressions. Server rendering is unfortunately not something I use often, so I don't really feel comfortable championing this feature and leading that testing. |
|
I wonder: is there a more incremental/opt-in approach, where panels be updated to read the size value, but rely on external code to actually set it initially for the SSR case? (Obviously we could document how to do that.) |
|
Thanks, that makes sense. Yeah I agree SSR adds some risk so keeping it opt-in sounds like a good idea. We can remove the logic from <PanelGroup autoSaveId="persistence1" direction="horizontal">
<Panel defaultSize={20} minSize={10} id="panel1" order={1}>
<PanelPersistScript autoSaveId="persistence1" panelId="panel1" />
<div>left</div>
</Panel>
</PanelGroup>I’ll rename For the persistence format change, I added a fallback so older data should still work fine. On testing: if all client tests pass we should be safe from regressions, and I can add a few more for the fallback logic. For SSR I might try adding one Playwright e2e test with the Next.js example repo, does that sound ok? |
|
Haven’t forgotten about this. Just busy with work. Will try to get back to you soonish |
…ter layout consistency
…e it form the Panel internals
…oupState in persist.ts
|
any update? |
|
No. Work has been very busy the past several days and honestly I don't have the mental bandwidth to really think through the ramifications of a change of this size right now. Sorry. If you're in a hurry to get this functionality shipped, you can always do a forked release for now. That's definitely the fastest path. |
|
Full disclosure: Because this is such a large change, and it would be a backwards breaking one (if we have to change |
here are my latest changes made on my own forked repo, I fixed the required order thing, now it's auto assigned and saved in local storage, so user don't need to set it explicitly anymore. also I moved the panel size css var to next thing I wanna try is render just one also what if we merge this into a beta branch and release it as 3.1.0-beta.1, I’d like to avoid publishing another npm package cause it's hard to find a good name. |
…ate persist logic
|
Cool, cool. Thanks for the update!
I started a branch this weekend exploring some ideas for how a next major
API might look. If I end up moving forward with that branch, I’ll try to
fold this in (in some form)
…On Sun, Nov 2, 2025 at 5:04 PM Ivica Batinić ***@***.***> wrote:
*isBatak* left a comment (bvaughn/react-resizable-panels#521)
<#521 (comment)>
Full disclosure: Because this is such a large change, and it would be a
backwards breaking one (if we have to change order to a required prop)
I'm going to try to find some time to re-think the API at a higher level.
There may be other changes I'd like to make too.
here <https://github.com/isBatak/react-resizable-panels/pull/1/files> are
my latest changes made on my own forked repo, I fixed the required order
thing, now it's auto assigned and saved in local storage, so user don't
need to set it explicitly anymore.
also I moved the panel size css var to PanelGroup (related to this comment #520
(comment)
<#520 (comment)>),
this makes render cheaper and we only need one PersistScript per group now.
https://github.com/user-attachments/assets/73d27239-ad53-4750-8848-bc4653e6d872
next thing I wanna try is render just one PersistScript for all local
storage entries and move css vars to :root. this will remove need for
suppressHydrationWarning on PanelGroup. the idea is to use a fallback var
for flex-grow like flex-grow: var(--panel-${order}-size,
var(--panel-${autoSaveId}-${order}-size)); where
--panel-${autoSaveId}-${order}-size is injected to :root by the
PersistScript.
—
Reply to this email directly, view it on GitHub
<#521 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAHHHPGEUWFH3AJNX5GTET32Z5YTAVCNFSM6AAAAACJT2MB6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINZYGQYDOMZZGA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
I just managed to implement this part too
here is the commit isBatak@170b782
I'm amazed at how well this turned out! |
feat: move css vars to panelGroup for better performance
|
Wanted to share a quick update here. I'm only able to work on this a little each day because my day job is pretty intense right now, but I think I can make a few nice API simplifications in my version 4 branch:
I'm not totally sure how the CSS variable stuff fits into that yet but I assume your work in this branch has plenty of useful information there. (Thanks!) I'm thinking if |
|
Thanks for the update! Totally understand about the limited time, I appreciate you still making progress on this. About the “no order props” change, my implementation relies heavily on the order number. I use it as a unique identifier for each panel together with autoSaveId. We can’t just replace order with id because useId generates non-constant values, so anything saved to local storage could change after a refresh. For example: So we’d need to keep some kind of stable order reference for these parts to work. |
My latest implementation of |
|
RE: the
I think we may be able to come up with a heuristic that supports this without needing to require both RE: |
This PR explores an approach to eliminate layout shift during SSR hydration by persisting panel sizes using inline scripts that execute before React hydration.
Changes Added
New Workspace Project
examples/nextjs) to test and demonstrate server-side rendering behaviorNew Component:
PersistScriptPersistScript.tsxcomponent that renders an inline<script>tag in each panelPanel Component Updates
Panel.tsto renderPersistScriptinside each panel whenautoSaveIdis providedsuppressHydrationWarningattribute to panel elements to handle the dynamic script injectiondata-panel-orderattribute to enable script to match panels with their saved stateStorage Format Changes
number[]toPanelLayoutItem[]:serialization.tsto handle both old and new formats for backward compatibilityorderto reliably match saved sizes even when panels are reorderedBreaking change
orderprop is required for this feature to work properlyTODO
suppressHydrationWarningrequirement - Find alternative approach (e.g., global CSS variables scoped by groupId + order:--panel-size-<groupId>-<order>)Handle customstorageprop - Decide what to do when users provide custom storage implementationOpen Questions
number[]format indefinitely?storageprop interact with the persistence script?Recordings