Skip to content

fix(editors): hoist ToolbarButton (static-components ×9) + restore live toolbar active states - #88

Merged
tbcsec merged 1 commit into
mainfrom
fix/react-hooks-batch1-static-components
Jul 27, 2026
Merged

fix(editors): hoist ToolbarButton (static-components ×9) + restore live toolbar active states#88
tbcsec merged 1 commit into
mainfrom
fix/react-hooks-batch1-static-components

Conversation

@tbcsec

@tbcsec tbcsec commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Batch 1 of 3 for #38.

Lint fix: ToolbarButton was declared inside both editors' render bodies — a new component type every render, so React remounted the button subtree each parent render (react-hooks/static-components, 9 warnings → 0). The two definitions were byte-identical; they're now one shared module-scope component. Warning count: 28 → 18, other rules untouched.

Bug found during live verification: toolbar active-state highlights have been frozen since the TipTap 3 migration (#69) — v3's useEditor defaults shouldRerenderOnTransaction to false (marked legacy-to-be-removed), so editor.isActive(...) evaluated in render never refreshed. Fixed the v3-idiomatic way: useEditorState with a selector over the active flags, re-rendering exactly when a flag flips (React-Compiler-friendly, per-keystroke-re-render-free).

Verification (demo stack, both editors):

  • CollabNote (challenge scratchpad): B/I/Code/List render from the shared component, room binds Live, highlight tracked bold→unbold→rebold across selections, focus stayed in the editor after toolbar clicks.
  • RichTextEditor (challenge editor): clean 9/9 pass — plain selection inactive, bold + H2 apply and highlight, all toggles restored, document left as found. No console errors.
  • tsc clean · eslint 0 errors / 18 warnings (the remaining Burn down the 27 react-hooks v7 (React Compiler) lint warnings #38 batches) · vitest 130/130 · production build untested locally (CI covers it).

🤖 Generated with Claude Code

…ar active states

Two fixes to the rich-text/collab editor toolbars (#38 batch 1 of 3):

- ToolbarButton was declared inside both editors' render, so React saw a new
  component type every render and remounted the buttons each time
  (react-hooks/static-components, 9 warnings — all gone). The two copies were
  identical; they're now one shared module-scope component
  (ui/editor-toolbar-button.tsx).

- Found during verification: toolbar active-state highlights have been frozen
  since the TipTap 3 migration (#69) — v3's useEditor no longer re-renders the
  host component on editor transactions (v2 did; the compat flag is marked
  legacy). Active flags are now derived via useEditorState, which re-renders
  exactly when a selected flag changes. Live-verified in both editors: bold/H2
  highlight on selection, track toggle on/off, focus stays in the editor.

Co-Authored-By: Claude <noreply@anthropic.com>
@tbcsec
tbcsec merged commit 1098d65 into main Jul 27, 2026
4 checks passed
@tbcsec
tbcsec deleted the fix/react-hooks-batch1-static-components branch July 27, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant