feat: split runtime/build server entries to exclude static routes from runtime bundle#1974
feat: split runtime/build server entries to exclude static routes from runtime bundle#1974TiwariLokesh wants to merge 2 commits intowakujs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
dai-shi
left a comment
There was a problem hiding this comment.
Thanks for working on it.
Instead of pruning static route modules after build, this change prevents fully static routes from entering the runtime module graph in the first place.
Sounds good.
We have waku/router on top of waku/minimal api. I wonder which is responsible to this capability. If it's waku/minimal related, we should work on it first, without caring waku/router much. (At least, the PR must be separated.)
| import path from 'node:path'; | ||
| import { EXTENSIONS, SRC_MIDDLEWARE, SRC_PAGES } from '../constants.js'; | ||
|
|
||
| export const getManagedServerEntry = (srcDir: string) => { |
There was a problem hiding this comment.
I'm not sure if I 100% follow the idea, but it shouldn't be managed mode only. So, changing code here seems not ideal.
| getConfigs: async (context?: { mode?: 'runtime' | 'build' }) => { | ||
| const mode = context?.mode || 'runtime'; |
There was a problem hiding this comment.
The change here is not nice and not acceptable. only define-router should be responsible to this capability.
There was a problem hiding this comment.
Thanks for pointing this out!
I've updated the implementation so that runtime/build filtering is handled entirely in define-router.
create-pages.tsx is now mode-agnostic as suggested.
Let me know if this looks better.
|
Actually, while not sure, this might be somewhat related with #1790, which I'm hoping to tackle sometime soon. |
|
Thanks for the feedback! You're right - the current implementation mixes router-level responsibility with managed mode logic. I'll revise the PR to:
I'll push an updated version shortly. |
|
Thanks for the detailed review! I've pushed an update addressing the feedback:
Now Build verification: Please let me know if there’s anything else I should adjust. |
dai-shi
left a comment
There was a problem hiding this comment.
Please let me know if there’s anything else I should adjust.
Don't expect this to be merged very soon. There are many things to consider some design decisions as I noted.
Meanwhile, make this PR minimal. Please don't change unrelated files. Review changes before pushing. For now, the quality feels AI generation level.
| @@ -1,5 +1,4 @@ | |||
| import { EXTENSIONS, SRC_MIDDLEWARE, SRC_PAGES } from '../constants.js'; | |||
|
|
|||
| ); | ||
| return resolved ? resolved : '\0' + source; | ||
| } | ||
| if (source === 'virtual:vite-rsc-waku/server-entry-build-inner') { |
There was a problem hiding this comment.
Any difference between -runtime-inner and -build-inner?
|
marking draft until we choose some design decisions. |
Summary
This PR addresses #1912 by introducing a proper architectural separation between runtime and build server entries.
Instead of pruning static route modules after build, this change prevents fully static routes from entering the runtime module graph in the first place.
Motivation
Currently, routes marked with
render: "static"are still bundled into the runtime server output even though they are only needed during SSG. This increases the production bundle size (e.g. large OpenGraph libraries, WASM blobs) and can cause deployment size constraints in environments like Cloudflare Workers.The previous workaround relied on post-build pruning. This PR removes that approach and replaces it with a cleaner graph-level separation.
What Changed
1. Runtime / Build Entry Split
Introduced two separate virtual server entries:
virtual:vite-rsc-waku/server-entry-runtimevirtual:vite-rsc-waku/server-entry-buildRuntime and build now generate independent module graphs.
2. Managed Mode Runtime Exclusion
In managed
fsRoutermode:import.meta.globnegative patterns.3. Mode-Aware Router Resolution
getConfigs({ mode })is now propagated throughdefine-router.mode: "runtime".mode: "build".4. Removed Post-Build Pruning
build-static-files.tsno longer performs file-level pruning.Static route exclusion is now handled at graph-construction time instead of cleanup time.
Result
Notes
Static route detection in managed mode is heuristic-based (literal
render: "static"detection) and conservative to avoid accidentally excluding dynamic routes.Custom server entries may still bundle static modules if explicitly imported.