Skip to content

Extend lazy server imports to route handlers and Pages - #99541

Merged
jimmyhmiller merged 2 commits into
canaryfrom
jimmym/lazy-ssr-followups
Oct 22, 2026
Merged

jimmyhmiller merged 2 commits into
canaryfrom
jimmym/lazy-ssr-followups

Conversation

@jimmyhmiller

Copy link
Copy Markdown
Contributor

Enable development-only lazy imports for Node.js route handlers, Pages API routes, and Pages SSR while keeping startup entries eager.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 79c9a7d

@jimmyhmiller
jimmyhmiller force-pushed the jimmym/lazy-ssr-followups branch from c37e58f to 032729b Compare October 2, 2026 14:30
@jimmyhmiller
jimmyhmiller requested a review from a team October 7, 2026 15:03
@jimmyhmiller
jimmyhmiller force-pushed the jimmym/lazy-ssr-followups branch from 032729b to 775fc97 Compare October 7, 2026 15:05
Enable development-only lazy imports for Node.js route handlers,
Pages API routes, and Pages SSR while keeping startup entries eager.
@jimmyhmiller
jimmyhmiller force-pushed the jimmym/lazy-ssr-followups branch from 775fc97 to 6632217 Compare October 9, 2026 17:52
@github-actions github-actions Bot added tests Turbopack Related to Turbopack with Next.js. labels Oct 9, 2026
Comment thread crates/next-api/src/project.rs Outdated
Comment on lines 1830 to 1836
lazy_dynamic_imports: if supports_lazy_dynamic_imports {
self.next_config()
.turbopack_lazy_dynamic_imports_ssr(*self.next_mode().await?)
} else {
Vc::cell(false)
},
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not do Vc::cell(false) here

If you disable the feature flag, then you have two possible sources for the Vc containing false:

  • turbopack_lazy_dynamic_imports_ssr() returns Vc::cell(false)
  • the literal Vc::cell(false) in the else branch.

And then you'd get two different invocations of get_server_chunking_context_with_client_assets returning an identically behaving but unique chunking context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you enable the feature flag, you would (intentionally) get two different chunking contexts for instrumentation and middleware.
This would be a problem if you have modules that are chunked by multiple chunking contexts. But I think this should be fine as we have separate middleware and instrumentation module contexts anyway, so there is no actual module overlap anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are totally right. Sorry I missed this.

Comment on lines +1296 to +1297
true, // client_assets
true, // supports_lazy_dynamic_imports

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we want an options struct here, but 2 isn't exactly worth it just yet 🤷

@jimmyhmiller
jimmyhmiller requested a review from mischnic October 20, 2026 15:03
@jimmyhmiller
jimmyhmiller enabled auto-merge (squash) October 21, 2026 15:58
@jimmyhmiller
jimmyhmiller merged commit 50bf604 into canary Oct 22, 2026
220 of 222 checks passed
@jimmyhmiller
jimmyhmiller deleted the jimmym/lazy-ssr-followups branch October 22, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants