next.js
f270834d - [dynamicIO] fix: do not apply import tracking transform in edge (#79284)

Commit
254 days ago
[dynamicIO] fix: do not apply import tracking transform in edge (#79284) Dynamic import tracking should never be applied to edge runtime code, because: 1. `dynamicIO` prerendering is not supported for edge 2. the implementation of `dynamicIO` prerendering relies on node-specific APIs. I missed this in #74152. This PR fixes a couple things: - We no longer apply the dynamic import tracking to any edge modules - Just to be safe, `trackDynamicImport` and `new CacheSignal` will now throw if it's called from the edge runtime - However, if `track-module-loading` does end up in an edge module, we don't want to error at the top-level when creating `moduleLoadingSignal`, so it is now initialized lazily. This is a bit ugly, but `AppRouteRouteModule` currently pulls all prerendering-related code in at the top level (instead of e.g. a conditional `require()` when prerendering), so it *is* included in edge route handlers, even if unused. - this also required changing `__next_require__`/`__next_chunk_load__` to only track module loading in DIO prerenders, otherwise we'd attempt to create `moduleLoadingSignal` in edge RSC too I also fixed a potential unhandled rejection in `CacheSignal.trackRead`, because `.finally` rejects even if the original error was caught somewhere else. (thanks for finding this one @gnoff!)
Author
Parents
Loading