Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1003,4 +1003,58 @@ describe('ReactDOMServerPartialHydration', () => {
let div = container.getElementsByTagName('div')[0];
expect(ref.current).toBe(div);
});

it('can client render nested boundaries', async () => {
let suspend = false;
let promise = new Promise(() => {});
let ref = React.createRef();

function Child() {
if (suspend) {
throw promise;
} else {
return 'Hello';
}
}

function App() {
return (
<div>
<Suspense
fallback={
<React.Fragment>
<Suspense fallback="Loading...">
<Child />
</Suspense>
<span>Inner Sibling</span>
</React.Fragment>
}>
<Child />
</Suspense>
<span ref={ref}>Sibling</span>
</div>
);
}

suspend = true;
let html = ReactDOMServer.renderToString(<App />);

let container = document.createElement('div');
container.innerHTML = html + '<!--unrelated comment-->';

let span = container.getElementsByTagName('span')[1];

suspend = false;
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
root.render(<App />);
Scheduler.unstable_flushAll();
jest.runAllTimers();

expect(ref.current).toBe(span);
expect(span.parentNode).not.toBe(null);

// It leaves non-React comments alone.
expect(container.lastChild.nodeType).toBe(8);
expect(container.lastChild.data).toBe('unrelated comment');
});
});
23 changes: 13 additions & 10 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,14 @@ function getNextHydratable(node) {
}
if (enableSuspenseServerRenderer) {
if (nodeType === COMMENT_NODE) {
break;
}
const nodeData = (node: any).data;
if (
nodeData === SUSPENSE_START_DATA ||
nodeData === SUSPENSE_FALLBACK_START_DATA ||
nodeData === SUSPENSE_PENDING_START_DATA
) {
break;
const nodeData = (node: any).data;
if (
nodeData === SUSPENSE_START_DATA ||
nodeData === SUSPENSE_FALLBACK_START_DATA ||
nodeData === SUSPENSE_PENDING_START_DATA
) {
break;
}
}
}
}
Expand Down Expand Up @@ -691,7 +690,11 @@ export function getNextHydratableInstanceAfterSuspenseInstance(
} else {
depth--;
}
} else if (data === SUSPENSE_START_DATA) {
} else if (
data === SUSPENSE_START_DATA ||
data === SUSPENSE_FALLBACK_START_DATA ||
data === SUSPENSE_PENDING_START_DATA
) {
depth++;
}
}
Expand Down