Skip to content

Commit 0cb3512

Browse files
committed
fix(compat): avoid materializing undefined props after suspense
1 parent 0405c33 commit 0cb3512

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

compat/test/browser/suspense.test.jsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,49 @@ describe('suspense', () => {
106106
});
107107
});
108108

109+
it('should not materialize undefined DOM props when suspense resumes', () => {
110+
const LazyComp = () => <span>Done</span>;
111+
112+
/** @type {() => Promise<void>} */
113+
let resolve;
114+
const Lazy = lazy(() => {
115+
const p = new Promise(res => {
116+
resolve = () => {
117+
res({ default: LazyComp });
118+
return p;
119+
};
120+
});
121+
122+
return p;
123+
});
124+
125+
render(
126+
<Suspense fallback={<span>Loading</span>}>
127+
<>
128+
<input id="test-input" type="text" maxLength={undefined} />
129+
<textarea id="test-textarea" minLength={null} />
130+
<Lazy />
131+
</>
132+
</Suspense>,
133+
scratch
134+
);
135+
rerender();
136+
137+
expect(scratch.innerHTML).to.eql(`<span>Loading</span>`);
138+
139+
return resolve().then(() => {
140+
rerender();
141+
142+
const input = scratch.querySelector('#test-input');
143+
expect(input.getAttribute('maxlength')).to.equal(null);
144+
expect(input.maxLength).to.equal(-1);
145+
146+
const textarea = scratch.querySelector('#test-textarea');
147+
expect(textarea.getAttribute('minlength')).to.equal(null);
148+
expect(textarea.minLength).to.equal(-1);
149+
});
150+
});
151+
109152
it('should handle lazy component that rejects without returning a component', async () => {
110153
const errorSpy = vi.fn();
111154
let renderCount = 0;

src/diff/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ function diffElementNodes(
595595
checked = value;
596596
} else if (
597597
(!isHydrating || typeof value == 'function') &&
598-
(oldProps[i] !== value || shouldRevalidateProps)
598+
(oldProps[i] !== value || (shouldRevalidateProps && value != NULL))
599599
) {
600600
setProperty(dom, i, value, oldProps[i], namespace);
601601
}

0 commit comments

Comments
 (0)