Skip to content
Source
Sign inSign up
TanStack/redact

fix: restore controlled form controls after onChange #116

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

Showing 10 changed files with 11 additions and 1 deletion (loading 7).

x
0 of 10 viewed, 10 left
5 additions and 0 deletions.changeset/restore-controlled-inputs.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/redact': patch
+---
+​
+Restore a controlled input's, textarea's or select's rendered value, and a checkbox's or radio group's checked state, after its change handlers run, including after hydration. An edit, click or choice the app does not accept no longer stays in the DOM. ([#115](https://github.com/TanStack/redact/issues/115))
3 additions and 0 deletionspackages/redact/src/dom/features/hydration/full.tsModified
View file
@@ -287,6 +287,9 @@
// Form defaults precede event registration so input type owns event mapping.
if (tag === 'input' || tag === 'textarea')
queueHydrationFormState(candidate as Element, props, tag);
+ // Hydration skips the form syncs, which record props for controlled restores.
+ if (tag === 'input' || tag === 'textarea' || tag === 'select')
+ (candidate as any).__p = props;
hydrateProps(fiber, candidate as Element, props, tag, isSvg);
// React SSR adds transport fields for progressively enhanced Server Actions.
// They have no corresponding client fibers and must not consume child slots.
3 additions and 1 deletionpackages/redact/src/dom/features/portal/full.tsModified
View file
@@ -1,11 +1,13 @@
import { FiberTag, type Fiber, type ReactNode } from '../../../core';
import { REACT_PORTAL_TYPE } from '../../../react';
+import { listenForRestores } from '../../form-controls';
import { installRenderer, registerTypeMatcher, registerElementMarker, reconcileRaw, childrenToArray, } from '../../reconcile';
function renderPortal(fiber: Fiber): void {
- const { children } = fiber.v as {
+ const { children, container } = fiber.v as {
children: ReactNode;