Commit 85b2d674 authored by Tobias Koppers's avatar Tobias Koppers

Import interopDefault from Rust loader tree instead of template export

interopDefault is used as a free variable in the Turbopack-generated loader
tree code. Turbopack tree-shakes it from the template since it has no static
use there. Fix by explicitly adding the import from app_page_loader_tree.rs
when the generated code uses it, so the template does not need to export it.

The import remains in the template for webpack, which uses loadEntrypoint()
to inject treeCode as text and needs the binding in scope.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 71d9958f
...@@ -455,6 +455,18 @@ impl AppPageLoaderTreeBuilder { ...@@ -455,6 +455,18 @@ impl AppPageLoaderTreeBuilder {
}; };
self.walk_tree(loader_tree, true).await?; self.walk_tree(loader_tree, true).await?;
// interopDefault is used as a free variable in the loader tree code generated
// above (see write_metadata_item / write_static_metadata_item). Import it
// explicitly here so the template does not need to export it.
let interop_import = rcstr!(
"import { interopDefault } from 'next/dist/esm/server/app-render/interop-default' \
with { 'turbopack-transition': 'next-server-utility' };"
);
if self.loader_tree_code.contains("interopDefault") {
self.base.imports.insert(0, interop_import);
}
Ok(AppPageLoaderTreeModule { Ok(AppPageLoaderTreeModule {
imports: self.base.imports, imports: self.base.imports,
loader_tree_code: self.loader_tree_code.into(), loader_tree_code: self.loader_tree_code.into(),
......
...@@ -7,9 +7,10 @@ import { RouteKind } from '../../server/route-kind' with { 'turbopack-transition ...@@ -7,9 +7,10 @@ import { RouteKind } from '../../server/route-kind' with { 'turbopack-transition
import * as entryBase from '../../server/app-render/entry-base' with { 'turbopack-transition': 'next-server-utility' } import * as entryBase from '../../server/app-render/entry-base' with { 'turbopack-transition': 'next-server-utility' }
// interopDefault is used as a free variable in the INJECT:tree generated code // interopDefault is used as a free variable in the INJECT:tree generated code
// (see crates/next-core/src/app_page_loader_tree.rs), so it must remain in // (see crates/next-core/src/app_page_loader_tree.rs).
// this template's compiled output as a local binding named `interopDefault`. // - Turbopack: import is added explicitly by app_page_loader_tree.rs so that
// verbatimModuleSyntax ensures the import is preserved as-is. // it isn't tree-shaken from this module.
// - Webpack: import below provides it as a local binding for treeCode injection.
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
import { interopDefault } from '../../server/app-render/interop-default' with { 'turbopack-transition': 'next-server-utility' } import { interopDefault } from '../../server/app-render/interop-default' with { 'turbopack-transition': 'next-server-utility' }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment