mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #282] [MERGED] fix: strip server-only data-fetching exports from client bundles #441
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#441
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/282
Author: @southpolesteve
Created: 3/6/2026
Status: ✅ Merged
Merged: 3/6/2026
Merged by: @southpolesteve
Base:
main← Head:fix/strip-server-exports-from-client📝 Commits (2)
3c1afa5fix: strip getServerSideProps/getStaticProps from client bundles0e53c34Rewrite stripServerExports to use AST instead of regex📊 Changes
2 files changed (+409 additions, -0 deletions)
View changed files
📝
packages/vinext/src/index.ts(+127 -0)📝
tests/build-optimization.test.ts(+282 -0)📄 Description
Summary
vinext:strip-server-exports) that removesgetServerSideProps,getStaticProps, andgetStaticPathsexports from page modules in the client bundlefs, etc.) that would break or bloat the client bundle. Next.js does this via an SWC transform; this adds the equivalent for vinext.export function getServerSideProps() { return { props: {} }; }orexport const ... = undefined;) so the bundler can tree-shake their import chainspages/directory. API routes,_app,_document, and_errorare excluded.export function,export async function,export constarrow functions,export constsimple references, and TypeScript type annotations in parametersImplementation
The core logic is in a standalone
stripServerExports()function (exported as_stripServerExportsfor testing). It uses askipBalanced()helper for bracket-aware scanning that correctly handles nested braces, string/template literals, line/block comments, and TypeScript type annotations.Test plan
11 unit tests added to
build-optimization.test.tscovering:export async function getServerSidePropsstrippingexport function getStaticPropsstrippingexport async function getStaticPaths+getStaticPropstogetherexport constarrow function strippingexport constsimple reference strippingFull test suite (2142 tests) passes. Existing pages-router integration tests confirm no regressions.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.