Skip to content
Source
Sign inSign up
TanStack/redact

fix: restore controlled form controls without a change handler #117

Openbilalvur(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/117/headopened

Refs #115. Stacked on #116; this covers its first two "Not covered" items. Until #116 merges, this diff includes its commits; review only the last one (cd5644a).

React restores after every change event, handler or not (createAndAccumulateChangeEvent calls enqueueStateRestore), so a controlled control without onChange stays read-only and a click on a handler-less radio restores its group. #116 only marked the event for a restore from Redact listeners on the control, so both kept the edit.

What changes

  • Once a control is controlled (checked for checkbox and radio, value otherwise), recording its props adds one shared listener that marks the event as a handler does, also on hydration. #116's container listeners then restore it. Uncontrolled controls get none.
  • React's dev warning for value without onChange has no Redact counterpart; this adds none.

Size

+12 to +57 B gzip against #116; two entries go over budget. UNHANDLED_RESTORE_SIZE_ALLOWANCE holds the measured increments and needs your approval.

Not covered

  • Clicking an uncontrolled radio without handlers does not restore controlled radios in its group. React does.

Testing

On #116 the 7 new jsdom tests for handler-less controls fail, as do the handler-less input and radio browser tests; an eighth jsdom test guards against restoring uncontrolled inputs. Browser results hold in Chromium, Firefox and WebKit, and pnpm test:pr passes on Node 24.22.0.

I used Claude Code to write the fix and tests, and had it run the suites and a separate review pass.

    1. 🦋 Changeset detected

      Latest commit: cd5644ac54b7635f7b084e9444ea5a5df5e845fb

      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. Important

      Draft PR not reviewed

      Draft PRs are not automatically reviewed by default.

      • Trigger a manual review

      To automatically review draft PRs, update your CodeRabbit configuration:

      reviews:
        auto_review:
          drafts: true
      • 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
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.