Conversation
) This should work around an undesirable edge case with "click" events that was reported in #627, while still maintaining the performance optimization added in #638. I have published this change as alpha version `react-resizable-panels@4.5.9-alpha.0` @michaelboyles Please verify this fixes the "click" issue you reported @evanfrawley Sorry to ask, but can you confirm this change doesn't negatively impact the issue you reported in #637?
Related to #650
I have a three panel layout and am attempting to persist the absolute
width of some panels when conditionally rendering others, i.e. switching
between a 2 and 3 panel layout. I can do this via the `setLayout`
imperative API method, roughly something like this:
```ts
const lastLayout = useRef<Layout>(ref.current?.getLayout() ?? {})
// This is passed as the Group component's onLayoutChanged prop.
const handleLayoutChanged = (layout: Layout) => {
const next = {...layout}
const prev = lastLayout.current
const nextLength = Object.keys(next).length
const prevLength = Object.keys(prev).length
if (prevLength !== nextLength) {
// Persist these
if ('navigation' in next && 'navigation' in prev) {
next.navigation = prev.navigation
}
if ('sidebar' in next && 'sidebar' in prev) {
next.sidebar = prev.sidebar
}
// Apply remaining space to content
if ('content' in next && 'content' in prev) {
next.content = 100 - (next.navigation ?? 0) - (next.sidebar ?? 0)
}
ref.current?.setLayout(next)
}
lastLayout.current = next
onLayoutChanged(next)
}
```
However, currently `setLayout` doesn't seem to persist layouts to the
`inMemoryLayouts` cache. As a result I am finding that when panels
subsequently change (in my case on route change in my application), the
layout is I assume read from the stale cache, and the panels snap back
to the layout received by `handleLayoutChanged` prior to when I called
`setLayout`.
This fix just persists those layouts to the cache, which after testing
this locally, seems to work.
Let me know if you'd like more detail or a repro.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )