Skip to content

Restyle playground edit toggles and fix stale toggle state#1016

Merged
amadeus merged 2 commits into
mainfrom
mdo/edit-mood-toggle
Jul 21, 2026
Merged

Restyle playground edit toggles and fix stale toggle state#1016
amadeus merged 2 commits into
mainfrom
mdo/edit-mood-toggle

Conversation

@mdo

@mdo mdo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Redesigns the playground's per-file Edit toggle across all three views and fixes a state-sync bug surfaced by the new design.

  • Replace the bare "Edit" checkbox with a bordered pill button in all three playground views (CodeView, React Virtualizer, vanilla Virtualizer): a filled checkbox + "Editing" when active, an outline icon + "Edit" when idle.
  • Add a shared .playground-edit-toggle class in globals.css, driven by aria-pressed, with both state icons and both labels always present so CSS shows the matching pair.
  • Port the design to the vanilla Virtualizer view by building the button in plain DOM and inlining the two icon glyphs as SVG (the metadata slot is light-DOM, so the app stylesheet reaches it), flipping only aria-pressed on click.
  • Fix a stale-closure bug in the React Virtualizer (element) view where the toggle's pressed state lagged one click behind: renderHeaderMetadata read render-phase editing but was wrapped in useStableCallback (which only refreshes in a commit-phase insertion effect) while FileDiff invokes it during render. Switch that callback to a useCallback keyed on editing. The old native checkbox masked this; the new aria-pressed button made it visible.

mdo added 2 commits July 21, 2026 16:15
The playground's per-file "Edit" control was a bare checkbox in each of
the three views (CodeView, React Virtualizer, and vanilla Virtualizer).
It is now a bordered pill button: a filled checkbox plus "Editing" when
active, an outline icon plus "Edit" when idle.

Styling is shared through one `.playground-edit-toggle` class in
globals.css, driven by `aria-pressed`. Both state icons and both labels
are always present so CSS shows the matching pair. The vanilla view
builds its DOM by hand and inlines the two glyphs as SVG, so it only has
to flip the attribute; its metadata slot is light-DOM, so the app
stylesheet reaches it.
Toggle Edit on a file in the playground's React Virtualizer view: the
button's pressed state lagged one click behind, showing the previous
value instead of the current one.

renderHeaderMetadata read `editing` from the render closure but was
wrapped in useStableCallback, which only refreshes its inner ref in a
commit-phase insertion effect. FileDiff calls the callback during
render, so it ran the previous render's closure. Use a useCallback keyed
on `editing` so each toggle renders with the current value.
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jul 21, 2026 11:17pm
pierre-docs-diffshub Ready Ready Preview Jul 21, 2026 11:17pm
pierre-docs-trees Ready Ready Preview Jul 21, 2026 11:17pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
pierrejs-diff-demo Skipped Skipped Jul 21, 2026 11:17pm

Request Review

@amadeus
amadeus merged commit 13f6b07 into main Jul 21, 2026
6 checks passed
@amadeus
amadeus deleted the mdo/edit-mood-toggle branch July 21, 2026 23:19
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.

2 participants