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 @@ -169,7 +169,7 @@ function processLink(props: Object, formatContext: FormatContext): void {
return;
}
case 'stylesheet': {
preload(href, 'stylesheet', {
preload(href, 'style', {
crossOrigin: props.crossOrigin,
integrity: props.integrity,
nonce: props.nonce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ describe('ReactFlightDOM', () => {
media="(orientation: landscape)"
/>
<link rel="modulepreload" href="module-resource" />
<link rel="preload" as="stylesheet" href="css-resource" />
<link rel="preload" as="style" href="css-resource" />
</head>
<body>
<p>hello world</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3051,4 +3051,60 @@ describe('ReactFlightDOMBrowser', () => {
`);
}
});

it('should resolve a cycle between debug info and the value it produces when using a debug channel', async () => {
// Same as `should resolve a cycle between debug info and the value it produces`, but using a debug channel.

function Inner({style}) {
return <div style={style} />;
}

function Component({style}) {
return <Inner style={style} />;
}

const style = {};
const element = <Component style={style} />;
style.element = element;

let debugReadableStreamController;

const debugReadableStream = new ReadableStream({
start(controller) {
debugReadableStreamController = controller;
},
});

const rscStream = await serverAct(() =>
ReactServerDOMServer.renderToReadableStream(element, webpackMap, {
debugChannel: {
writable: new WritableStream({
write(chunk) {
debugReadableStreamController.enqueue(chunk);
},
close() {
debugReadableStreamController.close();
},
}),
},
}),
);

function ClientRoot({response}) {
return use(response);
}

const response = ReactServerDOMClient.createFromReadableStream(rscStream, {
debugChannel: {readable: debugReadableStream},
});

const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);

await act(() => {
root.render(<ClientRoot response={response} />);
});

expect(container.innerHTML).toBe('<div></div>');
});
});
23 changes: 15 additions & 8 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4300,14 +4300,21 @@ function emitDebugChunk(

const json: string = serializeDebugModel(request, 500, debugInfo);
if (request.debugDestination !== null) {
// Outline the actual timing information to the debug channel.
const outlinedId = request.nextChunkId++;
const debugRow = outlinedId.toString(16) + ':' + json + '\n';
request.pendingDebugChunks++;
request.completedDebugChunks.push(stringToChunk(debugRow));
const row =
serializeRowHeader('D', id) + '"$' + outlinedId.toString(16) + '"\n';
request.completedRegularChunks.push(stringToChunk(row));
if (json[0] === '"' && json[1] === '$') {
// This is already an outlined reference so we can just emit it directly,
// without an unnecessary indirection.
const row = serializeRowHeader('D', id) + json + '\n';
request.completedRegularChunks.push(stringToChunk(row));
} else {
// Outline the debug information to the debug channel.
const outlinedId = request.nextChunkId++;
const debugRow = outlinedId.toString(16) + ':' + json + '\n';
request.pendingDebugChunks++;
request.completedDebugChunks.push(stringToChunk(debugRow));
const row =
serializeRowHeader('D', id) + '"$' + outlinedId.toString(16) + '"\n';
request.completedRegularChunks.push(stringToChunk(row));
}
} else {
const row = serializeRowHeader('D', id) + json + '\n';
request.completedRegularChunks.push(stringToChunk(row));
Expand Down
Loading