Skip to content

fix(acls): keep the policy editor's search panel open - #699

Open
Murgeye wants to merge 1 commit into
tale:mainfrom
Murgeye:fix/acl-editor-search-panel
Open

Murgeye wants to merge 1 commit into
tale:mainfrom
Murgeye:fix/acl-editor-search-panel

Conversation

@Murgeye

@Murgeye Murgeye commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Closes #698

The search panel in the policy file editor closed on every re-render of Editor: after a single replace, while typing, or when the page revalidated in the background.

Cause

Editor passed a new extensions array and a new inline onChange function to <CodeMirror> on every render. @uiw/react-codemirror dispatches StateEffect.reconfigure whenever either changes identity. CodeMirror adds the search state lazily via StateEffect.appendConfig when the panel opens, so each reconfigure dropped it and closed the panel.

Fix

  • Hoist the extensions to a module-level constant.
  • Pass props.onChange (setCodePolicy) through directly.

This implements steps 1 (for Editor), 2, and 4 of the plan in #698. Passing props.onChange directly is equivalent to the suggested useCallback wrapper, without the extra hook. I left out the Differ change: react-codemirror-merge rebuilds the merge view whenever its Original/Modified props change, which happens on every render, so hoisting jsonc there wouldn't help.

Testing

No automated test, since the repo has no DOM/component test setup. Locally, I mounted the real Editor in a standalone Vite page and drove it with Playwright in Firefox, simulating background revalidation by re-rendering the parent:

  • Before: the panel closed after the first replacement, and after a parent re-render with no input.
  • After: the panel stays open through repeated replacements and re-renders.

Typecheck, lint, and unit tests pass. Also verified by hand in the running app (Firefox on macOS).

I left out the optional search() hardening (step 3); happy to add it if preferred.

🤖 Generated with help from Claude Code (Opus 5.5)

Pass stable extensions and onChange to CodeMirror so re-renders no longer
reconfigure the editor, which dropped the lazily added search state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Murgeye
Murgeye requested a review from tale as a code owner November 26, 2026 10:20

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: sound — the panel was lost because @uiw/react-codemirror's useCodeMirror effect reconfigures the editor whenever extensions or onChange change identity, and StateEffect.reconfigure discards the lazily appended search state. Stabilizing both identities fixes the cause rather than papering over the symptom.

Reviewed changes

  • Stable extensions — [shopify.jsonc(), policyLinter, lintGutter()] is hoisted to a module-level editorExtensions array declared after policyLinter, so its identity no longer changes per render.
  • Stable onChange — <CodeMirror> now receives props.onChange directly instead of an inline wrapper. The sole caller is setCodePolicy (a useState setter) at app/routes/acls/overview.tsx:195, so the identity is stable in practice; the extra ViewUpdate argument CodeMirror passes is simply ignored by the setter.
  • Changelog — one prose line under # Next → ## Fixes, correctly linked to #698.

Verified against the installed library: the reconfigure effect's remaining deps (theme, minHeight, maxHeight, editable, readOnly, basicSetup primitives) are all module constants or stable values here, so typing, a replace, and background revalidation no longer reconfigure. The omitted Differ work is correctly scoped out — react-codemirror-merge defaults destroyRerender to true and its Original/Modified children dispatch new store objects on every render, so hoisting jsonc alone genuinely would not help. oxlint and oxfmt --check are clean on both touched files.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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.

Policy editor's search panel closes on re-render (e.g., after a single replace)

1 participant