Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flight][Fizz] ping work within current task #28894

Closed
wants to merge 1 commit into from
Closed
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 @@ -20,6 +20,10 @@ export function scheduleWork(callback: () => void) {
callback();
}

export function scheduleEagerWork(callback: () => void) {
callback();
}

export function flushBuffered(destination: Destination) {}

export function beginWriting(destination: Destination) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('ReactDOMFizzServerNode', () => {
writable.on('finish', () => {
resolve();
});
writable.on('error', () => {
writable.on('error', pl => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param not used

Suggested change
writable.on('error', pl => {
writable.on('error', () => {

resolve();
});
});
Expand Down Expand Up @@ -589,6 +589,7 @@ describe('ReactDOMFizzServerNode', () => {
if (!hasLoaded) {
throw promise;
}
console.log('rendering');
Copy link

@Jesus-Rojas Jesus-Rojas Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove is unnecessary

Suggested change
console.log('rendering');
console.log('rendering');

rendered = true;
return 'Done';
}
Expand Down Expand Up @@ -617,12 +618,11 @@ describe('ReactDOMFizzServerNode', () => {
writable.end();

await jest.runAllTimers();
await completed;

hasLoaded = true;
resolve();

await completed;

expect(errors).toEqual([
'The destination stream errored while writing data.',
]);
Expand Down
3 changes: 3 additions & 0 deletions packages/react-noop-renderer/src/ReactNoopFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const ReactNoopFlightServer = ReactFlightServer({
scheduleWork(callback: () => void) {
callback();
},
scheduleEagerWork(callback: () => void) {
callback();
},
beginWriting(destination: Destination): void {},
writeChunk(destination: Destination, chunk: string): void {
destination.push(chunk);
Expand Down
3 changes: 3 additions & 0 deletions packages/react-noop-renderer/src/ReactNoopServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const ReactNoopServer = ReactFizzServer({
scheduleWork(callback: () => void) {
callback();
},
scheduleEagerWork(callback: () => void) {
callback();
},
beginWriting(destination: Destination): void {},
writeChunk(destination: Destination, buffer: Uint8Array): void {
write(destination, buffer);
Expand Down
4 changes: 3 additions & 1 deletion packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {describeObjectForErrorMessage} from 'shared/ReactSerializationErrors';

import {
scheduleWork,
scheduleEagerWork,
beginWriting,
writeChunk,
writeChunkAndReturn,
Expand Down Expand Up @@ -595,7 +596,7 @@ function pingTask(request: Request, task: Task): void {
pingedTasks.push(task);
if (request.pingedTasks.length === 1) {
request.flushScheduled = request.destination !== null;
scheduleWork(() => performWork(request));
scheduleEagerWork(() => performWork(request));
}
}

Expand Down Expand Up @@ -4430,6 +4431,7 @@ export function abort(request: Request, reason: mixed): void {
flushCompletedQueues(request, request.destination);
}
} catch (error) {
console.log('caught', error);
const errorInfo: ThrownInfo = {};
logRecoverableError(request, error, errorInfo);
fatalError(request, error);
Expand Down
3 changes: 2 additions & 1 deletion packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {enableFlightReadableStream} from 'shared/ReactFeatureFlags';

import {
scheduleWork,
scheduleEagerWork,
flushBuffered,
beginWriting,
writeChunkAndReturn,
Expand Down Expand Up @@ -1237,7 +1238,7 @@ function pingTask(request: Request, task: Task): void {
pingedTasks.push(task);
if (pingedTasks.length === 1) {
request.flushScheduled = request.destination !== null;
scheduleWork(() => performWork(request));
scheduleEagerWork(() => performWork(request));
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/react-server/src/ReactServerStreamConfigBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function scheduleWork(callback: () => void) {
callback();
}

export function scheduleEagerWork(callback: () => void) {
callback();
}

export function flushBuffered(destination: Destination) {
// WHATWG Streams do not yet have a way to flush the underlying
// transform streams. https://github.com/whatwg/streams/issues/960
Expand Down
4 changes: 4 additions & 0 deletions packages/react-server/src/ReactServerStreamConfigBun.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export function scheduleWork(callback: () => void) {
callback();
}

export function scheduleEagerWork(callback: () => void) {
callback();
}

export function flushBuffered(destination: Destination) {
// Bun direct streams provide a flush function.
// If we don't have any more data to send right now.
Expand Down
5 changes: 5 additions & 0 deletions packages/react-server/src/ReactServerStreamConfigEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export function scheduleWork(callback: () => void) {
setTimeout(callback, 0);
}

const resolved = Promise.resolve();
export function scheduleEagerWork(callback: () => void) {
resolved.then(callback);
}

export function flushBuffered(destination: Destination) {
// WHATWG Streams do not yet have a way to flush the underlying
// transform streams. https://github.com/whatwg/streams/issues/960
Expand Down
5 changes: 5 additions & 0 deletions packages/react-server/src/ReactServerStreamConfigNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export function scheduleWork(callback: () => void) {
setImmediate(callback);
}

const resolved = Promise.resolve();
export function scheduleEagerWork(callback: () => void) {
resolved.then(callback);
}

export function flushBuffered(destination: Destination) {
// If we don't have any more data to send right now.
// Flush whatever is in the buffer to the wire.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export opaque type Chunk = mixed; // eslint-disable-line no-undef
export opaque type BinaryChunk = mixed; // eslint-disable-line no-undef

export const scheduleWork = $$$config.scheduleWork;
export const scheduleEagerWork = $$$config.scheduleEagerWork;
export const beginWriting = $$$config.beginWriting;
export const writeChunk = $$$config.writeChunk;
export const writeChunkAndReturn = $$$config.writeChunkAndReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export function scheduleWork(callback: () => void) {
callback();
}

export function scheduleEagerWork(callback: () => void) {
callback();
}

export function beginWriting(destination: Destination) {
destination.beginWriting();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ export * from '../ReactServerStreamConfigFB';
export function scheduleWork(callback: () => void) {
// We don't schedule work in this model, and instead expect performWork to always be called repeatedly.
}

export function scheduleEagerWork(callback: () => void) {
// We don't schedule work in this model, and instead expect performWork to always be called repeatedly.
}