Skip to content

Commit

Permalink
Use setTimeout to schedule work on the server in Edge environments
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Mar 8, 2023
1 parent 49f7410 commit 83b420e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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().
global.setTimeout = cb => cb();

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

0 comments on commit 83b420e

Please sign in to comment.