Updated react dockview-demo CodeSandbox to reset relevant state on subsequent onReady calls

Strict Mode causes the Dockview component to render twice, causing onReady to be called twice, which puts two copies of DefaultLayout in state without resetting between calls.

A most-ideal solution would probably be to expose an onUnload hook or something like that, to be called after one onReady but before the next. Then, the state resets could be called in that hook. but this fix will at least ensure the Dockview-Demo codesandbox behaves nicely for the time being.
This commit is contained in:
zaxer2 2025-01-03 13:22:07 -05:00 committed by GitHub
parent 148a05a201
commit cd91f4a4d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -178,6 +178,11 @@ const DockviewDemo = (props: { theme?: string }) => {
const onReady = (event: DockviewReadyEvent) => { const onReady = (event: DockviewReadyEvent) => {
setApi(event.api); setApi(event.api);
setPanels([]);
setGroups([]);
setActivePanel(undefined);
setActiveGroup(undefined);
addLogLine(`Dockview Is Ready`);
event.api.onDidAddPanel((event) => { event.api.onDidAddPanel((event) => {
setPanels((_) => [..._, event.id]); setPanels((_) => [..._, event.id]);