Repository navigation
fix(toolbar): compute button state on first render - #1352
Draft
makhnatkin wants to merge 3 commits into
Draft
makhnatkin wants to merge 3 commits into
makhnatkin wants to merge 3 commits into
Conversation
Collaborator
Author
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/editor/src/toolbar/hooks.ts" line_range="31" />
<code_context>
- active: false,
- enabled: true,
- });
+ const [state, setState] = useState(() => getActionState(editor, {isActive, isEnable}));
const stateRef = useLatest(state);
</code_context>
<issue_to_address>
**Toolbar shows stale button state**
When a mounted toolbar receives a different editor or changed action predicates, including a same-length replacement list, `useState` retains the previous state, and a same-length list can pass the `state.length === actions.length` check. The passive effect applies the new state only after paint, so the toolbar briefly shows the prior enabled or active state.
Recompute or reset the action state synchronously when the editor or action inputs change, rather than waiting for the passive effect.
Also at `packages/editor/src/toolbar/hooks.ts:59-61`.
</issue_to_address>
Collaborator
Author
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/editor/src/toolbar/hooks.ts" line_range="36" />
<code_context>
+
+ // Computed during render, so changed props never show the previous state.
+ const state = getActionsState(editor, actions);
+ const latestRef = useLatest({editor, actions, state});
useEffect(() => {
</code_context>
<issue_to_address>
**Committed toolbar keeps stale state**
When a concurrent render with different editor or action props pauses, then the still-committed editor emits an update matching the work-in-progress state before that render is abandoned, `latestRef.current` exposes the speculative `editor`, `actions`, and `state` to the committed update listener, so `onUpdate` compares the committed editor's update against that snapshot, skips `rerender`, and leaves the toolbar showing stale button state.
Publish the listener snapshot only after the render commits, so abandoned work cannot replace the committed comparison state.
</issue_to_address>
Collaborator
Author
|
@sourcery-ai review |
Toolbar buttons rendered as enabled until an effect after paint applied the real state, so a remounted Undo button could be captured enabled. The punctuation boundaries visual test now waits for the split preview content instead of a fixed pause. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Button state is computed during render, so a changed editor or action list never shows the previous state until an effect runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
makhnatkin
changed the base branch from
test/yfm-table-menu
to
test/clipboard-stability
October 9, 2026 23:24
makhnatkin
force-pushed
the
test/extensions-stability
branch
from
October 9, 2026 23:24
2ba3db3 to
8ada4bd
Compare
makhnatkin
added this pull request to stack #1347
October 9, 2026 23:25
An abandoned concurrent render could replace the snapshot that the update listener compares against. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
makhnatkin
force-pushed
the
test/extensions-stability
branch
from
October 9, 2026 23:55
8ada4bd to
93800d0
Compare
This branch has not been deployed
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.
🤖 Generated with Claude Code
Summary by Sourcery
Render toolbar action states synchronously and make visual-test synchronization content-based.
Bug Fixes:
Enhancements:
Tests: