Skip to content
Source
Sign inSign up
TanStack/redact

fix: focus late-mounted autofocus controls during commit #132

Mergedtannerlinsleymerged 2 commits intomain fromtaren/autofocus-approvedmerged by tannerlinsley

tannerlinsleycommented

Fixes #131.

Late-mounted button, input, select and textarea elements with autoFocus receive focus during commit, after placement and before their ref and parent layout effects. Adopted hydration content and ordinary updates do not refocus. Existing host-control flags select the supported elements.

Validation: 2,051 tests passed, 91 skipped, plus types and package build verification. All 38 fixed size limits pass. The official compatibility comparison passes the exact approved rows, at most 52 bytes gzip and 62 bytes Brotli. Fresh native/main/candidate browser controls passed 45 cases across Chromium, Firefox and WebKit, including focus order and hydration followed by a late mount.

    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: 7d6296ed8a95339fcd9241a763115b121c4906df

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/redactPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 51ca9aa9-2c4b-43ea-a701-1a9e6b31648d
      Commits

      Reviewing files that changed from the base of the PR and between e0f9f4d8c9ddd585b469b290fe823ca1beba539f and 7d6296ed8a95339fcd9241a763115b121c4906df.

      Files selected for processing: 4
      • packages/redact/src/dom/reconcile.ts
      • scripts/compatibility-size-budget.d.mts
      • scripts/compatibility-size-budget.mjs
      • tests/compatibility-size-budget.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

      Walkthrough

      Newly mounted supported controls with autoFocus receive focus during commit. Existing and hydrated controls do not take this focus path. DOM prop handling, tests, and compatibility size-budget allowances are updated.

      Changes: Autofocus Behavior

      Layer / File(s)Summary
      Commit-time autofocus
      packages/redact/src/dom/dom.ts, packages/redact/src/dom/reconcile.ts, tests/autofocus-commit.test.tsx, tests/dom-prop-reductions.test.ts, .changeset/late-mounted-autofocus.md
      autoFocus no longer proceeds through DOM prop handling. On mount, renderHost schedules focus for supported, non-hydrated, non-SVG controls. Tests cover focus timing, updates, hydration, unsupported elements, portals, suspended renders, and multiple autofocus controls.
      Compatibility size allowance
      scripts/compatibility-size-budget.d.mts, scripts/compatibility-size-budget.mjs, tests/compatibility-size-budget.test.ts
      The size-budget script fingerprints autofocus inputs and applies per-row metric allowances only when the base and fingerprint match. Tests check matching and rejected cases.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Merge Risk: Minimal · up to 7d629

      No actionable merge-blocking risk remains from the reviewed change.

      Pre-merge checks: Passed 4 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…Write docstrings for the functions missing them to satisfy the coverage threshold.
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Description CheckPassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title checkPassedThe title clearly and concisely describes the main change: focusing late-mounted autofocus controls during commit.
      Linked Issues checkPassedIssue #131 requires client-mounted elements with autoFocus to receive .focus() after insertion. Hydrated elements and updates are not in the requirement. The reviewed head (compared with the merge…
      Out of Scope Changes checkPassedThe runtime changes in dom.ts and reconcile.ts implement #131 directly. The autofocus test file and the updated tests/dom-prop-reductions.test.ts cover the same behavior. The changeset documents…
      Full details: Linked Issues check

      Explanation

      Issue #131 requires client-mounted elements with autoFocus to receive .focus() after insertion. Hydrated elements and updates are not in the requirement. The reviewed head (compared with the merge base 577e376) meets this requirement. (1) packages/redact/src/dom/dom.ts: setProp returns early for autoFocus, so the autofocus attribute is no longer written by the client render path. (2) packages/redact/src/dom/reconcile.ts: renderHost schedules fiber.n.focus() through scheduleLifecycle when the host is not hydrated, is not SVG, and is an input, textarea, select, or button. The focus runs before attachRef, so it precedes the ref and parent layout effects. tests/autofocus-commit.test.tsx covers all four tags, focus order against refs and layout effects, hydration with no focus, updates with no refocus, unsupported tags, portals, abandoned suspended hosts, and subtree commit order. The reviewed tests do not show a missing coding requirement. The autofocus attribute remains optional for SSR output, as the issue allows. Verification is by source and test reading. I did not run the test suite.

      Full details: Out of Scope Changes check

      Explanation

      The runtime changes in dom.ts and reconcile.ts implement #131 directly. The autofocus test file and the updated tests/dom-prop-reductions.test.ts cover the same behavior. The changeset documents it. The size-budget changes in scripts/compatibility-size-budget.mjs and scripts/compatibility-size-budget.d.mts add a pinned allowance. It applies only when the comparison base is 577e376 and the input fingerprint matches. It covers only the autofocus rows with min, gzip, and brotli values. The allowance follows from the added bytes in this feature. The tests in tests/compatibility-size-budget.test.ts check that other bases, changed fingerprints, missing fingerprints, and unsupported metrics return zero. The approval text and the Tanner approval named in the PR description are not in the repository. I cannot verify them from the source. This does not show an unrelated change. No unrelated product behavior is identified.

      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 7 files.

      Resolution

      Write docstrings for the functions missing them to satisfy the coverage threshold.

      Finishing Touches
      Generate docstrings
      • Commit to this branch
      • Create a new PR
      Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      Share
      • Fix comments: Fix CodeRabbit comments on this PR
      packages/redact/src/dom/dom.ts line 11Resolvedby tannerlinsley
    3. This is updated for current main and ready for the remaining checks. The smaller focus guard keeps the fix within the newly approved comparison rows.

      AI review notes: Head 7d6296ed preserves the original branch history and includes the merged recovery fix. The full resolved checkout matches the independently validated candidate across 876 files.

      2,051 tests passed, 91 skipped, types and build passed, and all 38 fixed size limits passed. The official comparison passes with the six exact Brotli updates Tanner approved. Maximum growth is 52 bytes gzip and 62 bytes Brotli, no fixed limits were raised.

      Fresh browser checks passed all 45 native/main/candidate cases across three engines, including commit/ref/layout order, updates that must not refocus, and hydration followed by a late mount. Full source and security review found no new material issue. GitHub checks on this updated head still have to pass before merge.

    4. tannerlinsley merged this8432ac2

    5. tannerlinsley closed this

    6. This is merged now, thanks for the report.

      AI review notes: PR132 merged at 8432ac256f8cfd517c94d135eae1e3a5eec99b84 after all 65GitHub checks passed. The merged tree matches the locally tested head. Late-mounted supported autoFocus controls now focus during commit, before their ref and parent layout effects.

      Local validation passed 2,051tests, types/build, 38fixed size limits and the exact approved comparison rows, plus 45browser cases and 9closed-dialog React controls across three engines. Maximum measured growth is 52bytes gzip and 62bytes Brotli, no fixed limits were raised.

      Issue #131 closed automatically with the merge. This is on main, a package release is still separate.

Sign in to join this conversation.