-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dynamicIO] track Prerender environment name during dev
When rendering in dev we track environment name to pass along server logs to the browser. Today the environment name is the default "Server" however when `dynamicIO` is enabled we want to have logs in the first Task where rendering starts be tagged with the environment "Prerender". This will help us understand what work is happening in the "Prerender" phase and what is happening in the dynamic "Server" phase while developing in dev mode.v
- Loading branch information
Showing
3 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/next/src/server/app-render/app-render-render-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { InvariantError } from '../../shared/lib/invariant-error' | ||
|
||
/** | ||
* This is a utility function to make scheduling sequential tasks that run back to back easier. | ||
* We schedule on the same queue (setImmediate) at the same time to ensure no other events can sneak in between. | ||
*/ | ||
export function scheduleInSequentialTasks<R>( | ||
render: () => R | Promise<R>, | ||
followup: () => void | ||
): Promise<R> { | ||
if (process.env.NEXT_RUNTIME === 'edge') { | ||
throw new InvariantError( | ||
'`scheduleInSequentialTasks` should not be called in edge runtime.' | ||
) | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
let pendingResult: R | Promise<R> | ||
setImmediate(() => { | ||
try { | ||
pendingResult = render() | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}) | ||
setImmediate(() => { | ||
followup() | ||
resolve(pendingResult) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters