fix: sidebar title disappears when switching between two sidebars#2905
Open
nzjrs wants to merge 1 commit into
Open
fix: sidebar title disappears when switching between two sidebars#2905nzjrs wants to merge 1 commit into
nzjrs wants to merge 1 commit into
Conversation
Open sidebar A with `ElementSidebar.set_title("A")` followed by
`set_elements([a])`, then open sidebar B with `set_title("B")` followed
by `set_elements([b], key="b")`. Click back and forth between the two.
Steady state: `#side-view-title` contains only the back-arrow button,
no title text node after it. During each switch the title flashes for
a render frame then vanishes. Body content renders fine; only the
header title is lost.
The `set_title` handler writes the sideView atom, then the
`set_elements` handler reads `prev` in its updater and falls back to
`title: prev?.title || ''` when prev is undefined. Instrumenting the
updater with a `console.log` shows `prev` observed as undefined on
every `set_elements` call even though the preceding `set_title`
handler just wrote to the atom synchronously in the same tick.
Something in React 18 + Recoil 0.7.7's nextTree/Batcher interaction
drops the staged write across socket.io event callbacks; I did not
isolate the Recoil-internals bug.
Rather than chase the Recoil bug, stop coordinating state across two
events. Add `ElementSidebar.set(title, elements, key=None)` that emits
a single `set_sidebar` frame carrying all three fields, and a frontend
handler that writes the atom from the payload alone -- never reading
`prev` for state it did not produce. The existing `set_title` and
`set_elements` APIs and handlers are untouched for back-compat;
callers that migrate to `.set()` stop seeing the title loss.
|
This PR is stale because it has been open for 14 days with no activity. |
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.
I have buttons in the header which are used to switch between two sidebars (or rather, switch out the contents of the one
cl.ElementSidebarto make it look like two sidebars). I observer visual artefacts and inconsistency when doing this, specifically I replace the contents of it and its title regularly, yet sometimes only half of the replacement sticks, often the title replacement is ignored.To reproduce:
Open sidebar A with
ElementSidebar.set_title("A")followed byset_elements([a]), then open sidebar B withset_title("B")followed byset_elements([b], key="b"). Click back and forth between the two. Steady state:#side-view-titlecontains only the back-arrow button, no title text node after it. During each switch the title flashes for a render frame then vanishes. Body content renders fine; only the header title is lost.The
set_titlehandler writes the sideView atom, then theset_elementshandler readsprevin its updater and falls back totitle: prev?.title || ''when prev is undefined. Instrumenting the updater with aconsole.logshowsprevobserved as undefined on everyset_elementscall even though the precedingset_titlehandler just wrote to the atom synchronously in the same tick. Something in React 18 + Recoil 0.7.7's nextTree/Batcher interaction drops the staged write across socket.io event callbacks; I did not isolate the Recoil-internals bug.It's hard to finesse the Recoil to coordinate state across two events so I Add
ElementSidebar.set(title, elements, key=None)that emits a singleset_sidebarframe carrying all three fields, and a frontend handler that writes the atom from the payload alone and never readingprevfor state it did not produce. The existingset_titleandset_elementsAPIs and handlers are untouched for back-compat; callers that migrate to.set()stop seeing the title loss.Summary by cubic
Fixes the disappearing sidebar title when switching between sidebars by sending a single atomic update. Adds a new backend API and client handler to set title, elements, and key together without relying on prior state.
ElementSidebar.set(title, elements, key=None)to emit oneset_sidebarpayload; emptyelementscloses the sidebar.set_sidebarand setssideViewdirectly, avoiding the React 18 + Recoil batching race that dropped the title.set_titleandset_elementsfor back-compat; callers can migrate to.set()to prevent the flicker.keyandtitlematch; element URL hydration is preserved.Written for commit a58f84d. Summary will update on new commits.