feat!: improve Next.js App Router fidelity#38
Draft
kasperpeulen wants to merge 187 commits into
Draft
Conversation
commit: |
1b8cc3a to
dd360ce
Compare
This reverts commit 6df207a.
e3d45dd to
55752cc
Compare
…ure-cleanup refactor: organize Next fidelity adapter architecture
…nsform fix: generalize CJS browser boundaries
e7f2535 to
0a19ebc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes
vitest-plugin-rscmuch more useful for testing real Next.js App Router code in Vitest Browser Mode.Users can now test pages, layouts, Server Actions, redirects, cache updates, request state, fonts, images, metadata, and global CSS with fast Vitest browser tests instead of reaching for full E2E coverage for every App Router scenario.
🧭 App Router Feature Matrix
Page Router features are intentionally ignored.
Legend: ✅ supported · 🧪 partial/experimental · 🧩 mock/shim ·⚠️ not claimed · 🚫 unsupported
🧬 RSC Runtime
nextjs-vite: 🧪 Experimental browser RSC wrapper for stories; server-side resources usually still need mocks.🛣️ Real App Routes By URL
urlandroute, but no full app route discovery/render pipeline.renderServer({ url })discovers realapp/routes and renders them through Next loader trees and app-render.nextjs-vite: 🚫 Component stories only; it does not render real app routes by URL.🧱 Layout Tree Fidelity
nextjs-vite: 🧩 Manual App Router context from story parameters.🧭 Navigation And Links
next/navigationhooks andnext/linkwork in route-aware component tests.nextjs-vite: 🧩 Router/navigation APIs are mocked and logged as Storybook actions.📨 Server Actions
nextjs-vite: 🚫 Docs call Server Actions future work.🍪 Headers, Cookies, And Draft Mode
nextjs-vite: 🧩 Writable mocks forheaders(),cookies(), anddraftMode().♻️ Cache And Revalidation
refresh, tags, cached fetch, and action rerenders in focused tests.use cache, cache handlers, cache life profiles, and invalidation coverage.nextjs-vite: 🧩next/cacheexports are mock functions, not the real cache runtime.🚦
next.configRoutesnextjs-vite: 🧪 Loads Next config for env/build conveniences, but not as route-render behavior.🧱 Middleware, Proxy, And Request Pipeline
next.configheaders/redirects/rewrites are supported, but middleware/proxy files are not executed.nextjs-vite: 🚫 No real Next request pipeline; component stories run in an isolated preview.🖼️ Images
next/imageclient boundary,getImageProps, static imports through Next image loader, blur metadata, static media URLs, and preload behavior.nextjs-vite: ✅ Good component-story support, but static image metadata is implemented through Storybook/Vite-side image handling.🔤 Fonts
nextjs-vite: 🧪 Partial support; docs list unsupported font config, fallback, adjust, preload, and display behavior.🧾 Metadata And Metadata Routes
metadata,generateMetadata, viewport, robots, sitemap, manifest, static metadata images, and dynamic OG/Twitter images.nextjs-vite:next/headworks in stories, but App Router metadata route fidelity is not claimed.🎨 Global Styling And Tailwind
next/fontstyles/preloads are covered.nextjs-vite: ✅ Strong support for global CSS, Tailwind/PostCSS, and component-story styling setup.💅 CSS Modules, Sass, And Styled JSX
styled-jsxespecially still needs explicit Next SWC + server-inserted style coverage before we should claim it.nextjs-vite: ✅ Documents CSS Modules, Sass/SCSS, and styled-jsx support.🧪 Route Handlers
NextRequest,NextResponse, cookies,nextUrl, methods, streams, redirects/rewrites, andImageResponse. They are still notrenderServer({ url })targets.nextjs-vite:🏗️ Production And App Lifecycle Fidelity
nextjs-vite: 🚫 Optimized for Storybook preview/build, not Next production server fidelity.🧾 Quick Read
nextjs-vite: Stronger for isolated component authoring and styling conveniences, but mostly mocks App Router runtime behavior.What This Unlocks
Render a real app route
Test the actual page from your
app/directory by URL. Layouts, route groups, templates, parallel routes, metadata, CSS, and route-level states are included in the render.Test a component with route state
For smaller tests, render one component but still give it the route params and search params it expects.
Test Server Actions from the hydrated UI
Click buttons and submit forms. Actions can update data, set cookies, refresh the current route, redirect, or revalidate cached data.
Assert real client navigation and redirects
Code using
next/navigationandnext/linkcan be tested through normal browser interactions. After a client-side navigation or same-origin Server Action redirect, assertwindow.locationand the new UI.Use
next.configbehavior in testsRoute tests can exercise configured headers, redirects, and rewrites.
Test cache and revalidation flows
App code can use cached
fetch,unstable_cache,use cache,updateTag,revalidateTag, andrevalidatePath, while tests assert the user-visible result after an action.Cover fonts, images, CSS, and metadata
Pages using
next/font,next/image, static image imports,app/globals.css, metadata exports, and metadata routes can be rendered and asserted in browser tests.Test route handlers directly
Route handlers can be imported directly for focused tests around
NextRequest,NextResponse, cookies, redirects, rewrites, streams, andImageResponse.Documentation
The README now has user-facing setup and usage examples for the Next.js App Router helpers. The maintainer-facing architecture notes live separately in
docs/new-architecture.md.Validation
CI covers format, lint, typecheck, build, Vitest, preview package publication, and the Next.js
16.0,16.1,latest, andcanarycompatibility matrix.