fix: prevent blank page when switching workspaces after creating a new one#19
Merged
Conversation
…w one Root cause: after creating a new workspace, switching back to an existing workspace leaves the page blank. Two intertwined issues: 1. workspaceIdAtom was a Jotai derived atom depending on WOS cache updates — the async chain across multiple awaits in reinitWave could silently fail to trigger React re-render after a CreateWorkspace → SwitchWorkspace cycle. Changed to a writable PrimitiveAtom explicitly set via globalStore.set(). 2. Electron WebContentsView rendering pipeline could break when repositioning views from off-screen (-15000,-15000) back to (0,0). Changed switchworkspace to detach BrowserViews via removeChildView instead of positionTabOffScreen, giving Electron a clean attach cycle on reuse. Additional defensive fixes: - REUSE path now calls contentView.addChildView() to guarantee BrowserView is attached to the current window - getOrCreateWebViewForTab checks webContents.isDestroyed() to filter Electron-destroyed views (WaveTabView.isDestroyed is a separate custom property that doesn't reflect Electron teardown) - Sweep wcvCache in finalizePositioning for stale on-screen tabs - Remove 'init' CSS class from body in initWaveWrap finally - Set activeTabIdAtom and staticTabId before reinitWave - Make reloadAllWorkspaceTabs/loadAllWorkspaceTabs await all tab loads before considering initialization complete - Re-subscribe to WPS workspace events on reinit
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
After creating a new workspace, switching back to any existing workspace causes the entire window to render blank (no UI elements at all). Normal workspace switching without creating a new one works fine.
Root Cause — Two Intertwined Issues
1. workspaceIdAtom was a Jotai derived atom with unreliable async reactivity
workspaceIdAtomwas defined as a computed atom that derived its value from the WOS cache:During
reinitWave,WOS.reloadWaveObject()updates the WOS cache viaglobalStore.set(). In normal workspace switching, Jotai detects the change and triggers re-render. But after aCreateWorkspace -> SwitchWorkspacecycle, the async chain across multipleawaitcalls could silently break Jotai's dependency tracking — the atoms updated but React never re-rendered, leaving#mainwith zero children.Fix: Changed
workspaceIdAtomto a writablePrimitiveAtom<string>, explicitly set viaglobalStore.set(atoms.workspaceId, ws.oid)in bothinitWaveandreinitWave. Also setstaticTabIdandactiveTabIdAtomexplicitly before reinit.2. Electron WebContentsView rendering pipeline broke after off-screen positioning
The
switchworkspacehandler moved BrowserViews off-screen usingpositionTabOffScreen(setBounds({x: -15000, y: -15000, ...})). When switching back, repositioning from extreme negative coordinates back to(0,0)could cause the compositor to not resume rendering.Fix: Changed
switchworkspaceto detach BrowserViews viacontentView.removeChildView()instead ofpositionTabOffScreen. The reuse path'saddChildView()gives Electron a clean attach cycle.Additional Defensive Fixes
addChildView()in REUSE pathemain/emain-window.tswebContents.isDestroyed()checkemain/emain-tabview.tsWaveTabView.isDestroyedis a custom property not reflecting Electron teardownfinalizePositioningemain/emain-window.tswcvCachefor any tab belonging to this window still at (0,0)initCSS class from bodyfrontend/wave.ts<body class="init">which was never removedreloadAllWorkspaceTabsfrontend/wave.tsfrontend/wave.ts