Skip to content

Commit 42dbe45

Browse files
committed
fix(octane): skip value-property journal entry on adopted hydration path
Adopted hydration writes only the defaultValue mirror, not el.value. Journaling el.value caused rollback to assign it back, setting the dirty-value flag even when the string was unchanged, so a retry's attribute-only write would not update the displayed text. Compute the adopted status before journaling so the adopted path journals only defaultValue and ctrl metadata, not the value property.
1 parent f0af05c commit 42dbe45

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30849,8 +30849,28 @@ export function setValue(el: Element, value: unknown): void {
3084930849
HYDRATION_DRIVER!.presentationMiss(false);
3085030850
const input = el as HTMLInputElement | HTMLTextAreaElement;
3085130851
const ctrl = armControlled(el);
30852-
if (TRANSITION_JOURNAL !== null) journalControlled(el, 'value', 'defaultValue');
3085330852
const first = !ctrl.sawV;
30853+
// Adopted hydration writes only the defaultValue mirror, not the value
30854+
// property. Journaling el.value would cause rollback to assign it back,
30855+
// setting the dirty-value flag even when the string is unchanged, so a
30856+
// retry's attribute-only write would not update the displayed text.
30857+
const hydration = first && hydrating ? activeHydration() : null;
30858+
const adopted = hydration !== null && !hydration.isFresh(el);
30859+
if (TRANSITION_JOURNAL !== null) {
30860+
if (adopted) {
30861+
TRANSITION_JOURNAL.push(
30862+
JOURNAL_PROP,
30863+
el,
30864+
'defaultValue',
30865+
(STAGED_DOM?.view(input) ?? input).defaultValue,
30866+
);
30867+
const ctrlSnap = renderControlledState(el);
30868+
if (ctrlSnap !== undefined) journalObjectOnce(ctrlSnap);
30869+
journalBag();
30870+
} else {
30871+
journalControlled(el, 'value', 'defaultValue');
30872+
}
30873+
}
3085430874
ctrl.sawV = true;
3085530875
if (value == null) {
3085630876
if (process.env.NODE_ENV !== 'production' && !first && ctrl.v !== UNCONTROLLED)
@@ -30872,8 +30892,7 @@ export function setValue(el: Element, value: unknown): void {
3087230892
// keeps pre-hydration user input until the element's first real commit
3087330893
// or discrete event. A fresh structural replacement is client-built and
3087430894
// needs normal projection.
30875-
const hydration = hydrating ? activeHydration() : null;
30876-
if (hydration === null || hydration.isFresh(el)) {
30895+
if (!adopted) {
3087730896
// PROPERTY first (React initInput order): the write marks the control
3087830897
// DIRTY, so the attribute write below — and any later defaultValue
3087930898
// binding — can never drag the live value along.

0 commit comments

Comments
 (0)