Skip to content

Commit 32d09f0

Browse files
committed
Encode unfortunate case in test
1 parent bb585b1 commit 32d09f0

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

packages/react-dom/src/__tests__/ReactMount-test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,12 @@ describe('ReactMount', () => {
123123
expect(instance1 === instance2).toBe(true);
124124
});
125125

126-
it('should warn if mounting into left padded rendered markup', () => {
126+
it('does not warn if mounting into left padded rendered markup', () => {
127127
const container = document.createElement('container');
128128
container.innerHTML = ReactDOMServer.renderToString(<div />) + ' ';
129129

130-
expect(() =>
131-
ReactDOM.hydrate(<div />, container),
132-
).toErrorDev(
133-
'Did not expect server HTML to contain the text node " " in <container>.',
134-
{withoutStack: true},
135-
);
130+
// This should probably ideally warn but we ignore extra markup at the root.
131+
ReactDOM.hydrate(<div />, container);
136132
});
137133

138134
it('should warn if mounting into right padded rendered markup', () => {

packages/react-dom/src/__tests__/ReactRenderDocument-test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,31 @@ describe('rendering React components at document', () => {
368368
expect(testDocument.body.innerHTML).toBe('Hello world');
369369
});
370370

371-
it('renders over an existing text child without throwing', () => {
371+
it('cannot renders over an existing text child at the root', () => {
372372
const container = document.createElement('div');
373373
container.textContent = 'potato';
374374
expect(() => ReactDOM.hydrate(<div>parsnip</div>, container)).toErrorDev(
375375
'Expected server HTML to contain a matching <div> in <div>.',
376376
);
377+
// This creates an unfortunate double text case.
378+
expect(container.textContent).toBe('potatoparsnip');
379+
});
380+
381+
it('renders over an existing nested text child without throwing', () => {
382+
const container = document.createElement('div');
383+
const wrapper = document.createElement('div');
384+
wrapper.textContent = 'potato';
385+
container.appendChild(wrapper);
386+
expect(() =>
387+
ReactDOM.hydrate(
388+
<div>
389+
<div>parsnip</div>
390+
</div>,
391+
container,
392+
),
393+
).toErrorDev(
394+
'Expected server HTML to contain a matching <div> in <div>.',
395+
);
377396
expect(container.textContent).toBe('parsnip');
378397
});
379398

packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,26 +510,47 @@ describe('ReactDOMServerHydration', () => {
510510

511511
it('Suspense + hydration in legacy mode', () => {
512512
const element = document.createElement('div');
513-
element.innerHTML = '<div>Hello World</div>';
514-
const div = element.firstChild;
513+
element.innerHTML = '<div><div>Hello World</div></div>';
514+
const div = element.firstChild.firstChild;
515515
const ref = React.createRef();
516516
expect(() =>
517517
ReactDOM.hydrate(
518-
<React.Suspense fallback={null}>
519-
<div ref={ref}>Hello World</div>
520-
</React.Suspense>,
518+
<div>
519+
<React.Suspense fallback={null}>
520+
<div ref={ref}>Hello World</div>
521+
</React.Suspense>
522+
</div>,
521523
element,
522524
),
523525
).toErrorDev(
524526
'Warning: Did not expect server HTML to contain a <div> in <div>.',
525-
{withoutStack: true},
526527
);
527528

528529
// The content should've been client rendered and replaced the
529530
// existing div.
530531
expect(ref.current).not.toBe(div);
531532
// The HTML should be the same though.
532-
expect(element.innerHTML).toBe('<div>Hello World</div>');
533+
expect(element.innerHTML).toBe('<div><div>Hello World</div></div>');
534+
});
535+
536+
it('Suspense + hydration in legacy mode (at root)', () => {
537+
const element = document.createElement('div');
538+
element.innerHTML = '<div>Hello World</div>';
539+
const div = element.firstChild;
540+
const ref = React.createRef();
541+
ReactDOM.hydrate(
542+
<React.Suspense fallback={null}>
543+
<div ref={ref}>Hello World</div>
544+
</React.Suspense>,
545+
element,
546+
);
547+
548+
// The content should've been client rendered.
549+
expect(ref.current).not.toBe(div);
550+
// Unfortunately, since we don't delete the tail at the root, a duplicate will remain.
551+
expect(element.innerHTML).toBe(
552+
'<div>Hello World</div><div>Hello World</div>',
553+
);
533554
});
534555

535556
it('Suspense + hydration in legacy mode with no fallback', () => {

0 commit comments

Comments
 (0)