8000 [dynamicIO] fix: do not apply import tracking transform in edge by lubieowoce · Pull Request #79284 · vercel/next.js · GitHub
[go: up one dir, main page]

Skip to content

[dynamicIO] fix: do not apply import tracking transform in edge #79284

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

Merged
merged 6 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
disallow usage of CacheSignal and trackDynamicImport in edge runtime
  • Loading branch information
lubieowoce committed May 16, 2025
commit cc40e9a3597480d0ebf072e7ed1e4ab40e7caa89
4 changes: 3 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,5 +677,7 @@
"676": "Invariant: missing internal router-server-methods this is an internal bug",
"677": "`trackDynamicImport` should always receive a promise. Something went wrong in the dynamic imports transform.",
"678": "CacheSignal got more endRead() calls than beginRead() calls",
"679": "A CacheSignal cannot subscribe to itself"
"679": "A CacheSignal cannot subscribe to itself",
"680": "CacheSignal cannot be used in the edge runtime, because `dynamicIO` does not support it.",
"681": "Dynamic imports should not be instrumented in the edge runtime, because `dynamicIO` doesn't support it"
}
9 changes: 9 additions & 0 deletions packages/next/src/server/app-render/cache-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export class CacheSignal {

private subscribedSignals: Set<CacheSignal> | null = null

constructor() {
if (process.env.NEXT_RUNTIME === 'edge') {
// we rely on `process.nextTick`, which is not supported in edge
throw new InvariantError(
'CacheSignal cannot be used in the edge runtime, because `dynamicIO` does not support it.'
)
}
}

private noMorePendingCaches() {
if (!this.tickPending) {
this.tickPending = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { trackPendingImport } from './track-module-loading.external'
export function trackDynamicImport<TExports extends Record<string, any>>(
modulePromise: Promise<TExports>
): Promise<TExports> {
if (process.env.NEXT_RUNTIME === 'edge') {
throw new InvariantError(
"Dynamic imports should not be instrumented in the edge runtime, because `dynamicIO` doesn't support it"
)
}

if (!isThenable(modulePromise)) {
// We're expecting `import()` to always return a promise. If it's not, something's very wrong.
throw new InvariantError(
Expand Down
0