next.js
ac301f70 - [Segment Cache] Omit from bundle if flag disabled

Commit
298 days ago
[Segment Cache] Omit from bundle if flag disabled Alternative to https://github.com/vercel/next.js/pull/76597. This works by importing all Segment Cache related code through a single entry point (segment-cache.ts), and wrapping each export in a feature flag check. This fixes the size regression in v15.2 but long term I don't love this approach. Since experimental flags are an essential part of our workflow, we should establish a better pattern for dead code elimination. Ideally it would be done at the bundler level, like how React's build process works. In the React repo, you don't even need to add any extra configuration per experiment — if the code is not reachable, it gets stripped from the build automatically by Rollup. Or, shorter term, we could stub out experimental modules at build time by updating the build config, i.e. a more automated version of what I'm doing manually for this particular flag.
Author
Committer
Parents
Loading