Skip to content

refactor(ui): preserve modal entry focus through native refs - #177200

Merged
steipete merged 3 commits into
mainfrom
solid2/w-zero-component-modal-focus-targets
Oct 19, 2026
Merged

steipete merged 3 commits into
mainfrom
solid2/w-zero-component-modal-focus-targets

Conversation

@steipete

@steipete steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Modal entry focus still discovers renderer-owned autofocus controls by traversing the dialog DOM. This completes the native-ref cutover across all current Modal callers.

User Impact

No intended visible change: opening focus, input during opening, cancellation, retained drafts, nested dialogs, and return focus keep their existing behavior. No migration or configuration changes.

Why This Change Was Made

The Modal policy now receives its initial native target from the rendering owner and reads live callbacks from the host. The caller audit covers all 50 production Modal constructors, including cold and loaded command palettes, conditional file-preview controls, model setup, provider login, and chat confirmations. Dialogs without an autofocus target retain native dialog focus. Plugin content remains a deliberate foreign-DOM island and resolves its own native autofocus target.

Direct/composed JSX refs forward the native controls. Existing layout, scroll, and domain owners remain intact, and lazy module boundaries remain unchanged. The cold-shell fixture now awaits the real bridge commit and asserts natural focus instead of forcing it.

Evidence

Proof Result
Default tsrs, pnpm tsgo:ui Passed
Pinned Bun focused tests, one worker Modal 15 + Solid Modal 12 + cold palette 19 passed
Scoped format and UI lint Passed; five advisory style/reactivity warnings recorded
Isolated P2 autoreview Full cutover and final direct-ref correction reviewed
Paired production builds and strict performance Passed on the same machine against f95deb6e01d9
Startup JS gzip 324,139 → 324,127 B (−12 B); 7 requests
Startup CSS 38,500 B; one request on both sides
Synthetic captures Cold palette, native entry, plugin root entry; all three pairs byte-identical
Production Knip Same sole unused ws finding in extensions/signal/package.json on head and pinned base f95deb6e01d9; no new findings

The first cold-shell test run caught a fixture timing gap: its focus assertion preceded updateComplete. The corrected helper awaits that public boundary; the failed file alone was rerun. The unchanged liveValue helper emits an existing STRICT_READ_UNTRACKED diagnostic in the cold palette tests. Full browser and application proof runs through ci:full; no local E2E suite or parity run was used.

Touched-production checklist Before After
Rendering controllers 0 0
createEffect 4 4
createRenderEffect 0 0
untrack 4 4
addEventListener 0 0
DOM queries 11 11
Manual class strings / flush / owner escapes 0 0

The query total is unchanged because the generic Modal lookup is removed and the plugin adapter gains its explicitly owned foreign-DOM lookup. All 11 survivors are island queries: ten in components/markdown-tables.ts (lines 52, 69–71, 110, 135, 145, 186, 286, 303) and one in plugins/control-ui-components.ts:175.

The four existing effects are retained layout/scroll/imperative owners in command-palette-input.tsx:89, file-preview-modal.tsx:184, image-lightbox-content.tsx:452, and pages/plugins/credential-editor.tsx:73. Four intentional initial snapshots remain in command-palette-view.tsx:360, confirm-dialog-view.tsx:10, input-dialog-view.tsx:13, and pages/chat/components/file-draft-recovery-dialog-view.tsx:25.

Production LOC: 7,161 → 7,339. Tests: 2,439 → 2,482. Growth is native ref ownership at the existing rendering callers, plus the async focus-fixture assertions; no shared abstraction or new dependency was added.

Before: cold palette focus

After: cold palette focus

Before: native opening focus

After: native opening focus

Before: plugin root focus

After: plugin root focus

Completed CI attribution

Full ci:full run 39230437151 completed on 5ecf32a4ae59. Both real-Gateway shards, eight other browser shards, type/lint, performance, and security passed. Two failures are inherited:

Failed test Baseline evidence
chat-composer-plus-menu-loading.test.tsx — keeps the menu open and retries a failed content load Reproduced once on actual CI main parent 70276985de6f: same hidden-menu / inaccessible alert failure at line 142; 1 failed, 6 passed, default pinned Bun and one worker.
chat-details-changes.e2e.test.ts — Details change summary > observes only metadata while Details is presented and retains last-known changes on refresh failure Exact test and All changes— missing 12 files assertion also fail on latest completed scheduled main run 39225083411, head 125b5e20dc7c.

CI checkout 9cd8ffe51f08 has actual main parent 70276985de6f and reviewed head 5ecf32a4ae59; inspected failure-source objects are unchanged between that parent and the tested merge. Landing uses the authorized native inherited-failure route; failed checks remain recorded as failures.

Prepare caller-owned focus targets while retaining the autofocus fallback for pending caller migrations. Keep modal callbacks on the synchronous native host to avoid reactive reads during imperative publication.
@steipete steipete added the ci:full Keep ordinary native-locale CI selection on the next PR run. label Oct 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T09:33:08.740986Z 5ecf32a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ecf32a4ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

manual: boolean;
label: string;
description: string;
initialFocus?: () => HTMLElement | null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Reduce the refactor below its original production footprint

The required Solid refactor checklist says production LOC must decrease, but excluding tests this change adds 212 lines and removes 34 (+178) across 25 production files, largely to thread initialFocus refs through callers in place of one modal-owned lookup. This expands the focus contract and maintenance burden across unrelated dialogs rather than simplifying the owner; consolidate the registration in the modal primitive or otherwise shrink the production diff before landing.

AGENTS.md reference: ui/AGENTS.md:L3-L5

Useful? React with 👍 / 👎.

@steipete
steipete enabled auto-merge (squash) October 19, 2026 09:35
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces modal-owned autofocus lookup with native focus targets supplied by each rendering caller.

Example: Open the cold command palette and type “Summarize this project”.

  • Before: The modal finds the textarea through its autofocus attribute.
  • After: The palette supplies the textarea ref directly, preserving opening focus and typing.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The cutover is coherent and no actionable defect was found, but the visual evidence covers synthetic settled states and CI attribution is incomplete.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored refactor is outside the ordinary contributor-proof gate; inspected synthetic captures cover settled cold-palette and native-entry focus, while supplied tests exercise the real modal policy.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Dialog users need opening focus, typing, cancellation, and return focus to remain stable through the native-ref cutover.
Reason: The maintainer-authored direction completes a previously deferred cutover using existing renderers and the existing modal policy.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored refactor completes an intentional focus-ownership cutover that current main still lacks; no definite introduced defect was found.

Priority: P3
Reviewed head: 5ecf32a4ae5987452338437f70939049c21d16d8

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied settled captures do not demonstrate opening-time input or nested cancellation across Chromium and WebKit.
Agent review details

How this fits together

Control UI renderers provide native elements to the shared modal policy, which owns opening focus, cancellation, nested overlays, and return focus.

flowchart LR
  A[Dialog renderer] --> B[Native control ref]
  B --> C[Modal host]
  D[Plugin content adapter] --> C
  C --> E[Shared modal policy]
  E --> F[Native dialog and focus]
Loading

Technical review

Best possible solution:

Keep the shared modal lifecycle owner and explicit caller-owned focus refs, with DOM discovery confined to foreign content.

Do we have a high-confidence way to reproduce the issue?

This is a behavior-preserving refactor rather than a reported user bug; source confirms the DOM-discovery path being replaced.

Is this the best way to solve the issue?

The cutover follows the existing ref-ownership policy while preserving the modal's focus and cancellation decisions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a4c5e4019142.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b68c44c adds ui/src/components/modal-dialog.ts:168 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b68c44ca8f3c; files: ui/src/components/modal-dialog.ts)

PR surface

Source +178, Tests +43. Total +221 across 32 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 25 212 34 +178
Tests 7 94 51 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 32 306 85 +221

Review metrics

Metric Value Why it matters
Production versus test LOC Production +178; tests +43 Production growth threads native refs through existing callers; test growth strengthens opening-focus assertions without adding another lifecycle owner.

Labels

Label changes:

  • add P3: This is an internal ownership refactor with no intended user-visible behavior change.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is an internal ownership refactor with no intended user-visible behavior change.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 19, 2026, 5:47 AM ET / 09:47 UTC.

@steipete
steipete disabled auto-merge October 19, 2026 09:58
@steipete
steipete merged commit a2c0922 into main Oct 19, 2026
119 of 124 checks passed
@steipete
steipete deleted the solid2/w-zero-component-modal-focus-targets branch October 19, 2026 10:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
…w#177200)

* refactor(ui): pass explicit modal focus targets

Prepare caller-owned focus targets while retaining the autofocus fallback for pending caller migrations. Keep modal callbacks on the synchronous native host to avoid reactive reads during imperative publication.

* refactor(ui): pass the lightbox modal focus target

* refactor(ui): register native modal focus targets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui ci:full Keep ordinary native-locale CI selection on the next PR run. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant