Skip to content

Commit a250eb5

Browse files
committed
refactor(compat): remove redundant textarea hydration hook
1 parent edb975c commit a250eb5

3 files changed

Lines changed: 15 additions & 36 deletions

File tree

compat/src/render.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -309,26 +309,6 @@ options.vnode = vnode => {
309309
if (oldVNodeHook) oldVNodeHook(vnode);
310310
};
311311

312-
const oldDiffed = options.diffed;
313-
/** @type {(vnode: import('./internal').VNode) => void} */
314-
options.diffed = function (vnode) {
315-
if (oldDiffed) {
316-
oldDiffed(vnode);
317-
}
318-
319-
const props = vnode.props;
320-
const dom = vnode._dom;
321-
322-
if (
323-
dom != null &&
324-
vnode.type == 'textarea' &&
325-
'value' in props &&
326-
props.value !== dom.value
327-
) {
328-
dom.value = props.value == null ? '' : props.value;
329-
}
330-
};
331-
332312
// Only needed for react-relay and useSyncExternalStore hydration.
333313
function initRenderTracking(value) {
334314
if (!renderTrackingInitialized) {

compat/test/browser/textarea.test.jsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { createElement, render, hydrate, useState } from 'preact/compat';
2-
import ReactDOMServer from 'preact/compat/server';
32
import { setupScratch, teardown } from '../../../test/_util/helpers';
43
import { act } from 'preact/test-utils';
54

@@ -21,19 +20,19 @@ describe('Textarea', () => {
2120
expect(scratch.firstElementChild.value).to.equal('foo');
2221
});
2322

24-
it('should hydrate textarea value', () => {
25-
function App() {
26-
return <textarea value="foo" />;
27-
}
23+
it('should preserve textarea values when nullish values are uncontrolled', () => {
24+
for (const value of [null, undefined]) {
25+
const root = document.createElement('div');
26+
root.innerHTML = '<textarea></textarea>';
27+
root.firstChild.value = 'user';
28+
scratch.appendChild(root);
2829

29-
scratch.innerHTML = ReactDOMServer.renderToString(<App />);
30-
expect(scratch.firstElementChild.value).to.equal('foo');
31-
expect(scratch.innerHTML).to.be.equal('<textarea>foo</textarea>');
30+
hydrate(<textarea value={value} />, root);
31+
expect(root.firstChild.value).to.equal('user');
3232

33-
hydrate(<App />, scratch);
34-
expect(scratch.firstElementChild.value).to.equal('foo');
35-
36-
expect(scratch.innerHTML).to.be.equal('<textarea></textarea>');
33+
render(<textarea value={value} />, root);
34+
expect(root.firstChild.value).to.equal('user');
35+
}
3736
});
3837

3938
it('should alias defaultValue to children', () => {

test/browser/hydrate.test.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ describe('hydrate()', () => {
7777
expect(scratch.firstChild.defaultValue).to.equal('foo');
7878
});
7979

80-
it('should respect textarea value in hydrate', () => {
81-
scratch.innerHTML = '<textarea>foo</textarea>';
82-
hydrate(<textarea value="foo" />, scratch);
83-
expect(scratch.firstChild.value).to.equal('foo');
80+
it('should synchronize textarea values during hydration', () => {
81+
scratch.innerHTML = '<textarea>server</textarea>';
82+
hydrate(<textarea value="client" />, scratch);
83+
expect(scratch.firstChild.value).to.equal('client');
8484
});
8585

8686
it('should respect defaultChecked in hydrate', () => {

0 commit comments

Comments
 (0)