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

Use setTimeout to schedule work on the server in Edge environments #26348

Merged
merged 1 commit into from
Mar 8, 2023
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 @@ -15,6 +15,10 @@ global.ReadableStream =
global.TextEncoder = require('util').TextEncoder;
global.TextDecoder = require('util').TextDecoder;

// Don't wait before processing work on the server.
// TODO: we can replace this with FlightServer.act().
Copy link
Collaborator Author

@sebmarkbage sebmarkbage Mar 8, 2023

Choose a reason for hiding this comment

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

Need a better plan for testing "act" things in Flight/Fizz. There are other such todos in the Node.js tests already.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, jinx

global.setTimeout = cb => cb();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm gonna trust you that this makes sense 😆 figure we're probably going to have to rethink our testing strategy for Fizz/Flight soon regardless


let clientExports;
let webpackMap;
let webpackModules;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactServerStreamConfigEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type PrecomputedChunk = Uint8Array;
export opaque type Chunk = Uint8Array;

export function scheduleWork(callback: () => void) {
callback();
setTimeout(callback, 0);
}

export function flushBuffered(destination: Destination) {
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/__tests__/ReactFetchEdge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ global.Response = require('node-fetch').Response;
// Patch for Edge environments for global scope
global.AsyncLocalStorage = require('async_hooks').AsyncLocalStorage;

// Don't wait before processing work on the server.
// TODO: we can replace this with FlightServer.act().
global.setTimeout = cb => cb();

let fetchCount = 0;
async function fetchMock(resource, options) {
fetchCount++;
Expand Down