mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
151f099089
* fix: CSS imports from node_modules crash SSR (#270) When a node_modules package imports a `.css` file, SSR crashes with "Unknown file extension .css" because Vite externalizes node_modules by default — causing Node's native ESM loader to handle the import, which it can't do for non-JS files. Set `noExternal: true` on all server environments (Pages Router SSR, App Router RSC, App Router SSR) to force node_modules through Vite's transform pipeline. This matches Next.js behavior of bundling everything for SSR. Explicitly listed `external` packages (react, satori, resvg, yoga-wasm-web) take precedence per Vite's rules. Skipped for Cloudflare/Nitro targets which already bundle everything. * fix: externalize better-sqlite3 and fix test hermiticity - Add better-sqlite3 to ssr.external in better-auth fixture config. Native addon packages using `bindings` break when Vite transforms them (stack trace introspection fails). This mirrors Next.js's serverExternalPackages — users with native addons must externalize them. - Fix Pages Router CSS test mutating real workspace node_modules. Previously symlinked tmpDir/node_modules → repo root, then created fake-css-lib inside the symlink target, leaking into the real workspace. Now creates a real node_modules dir and symlinks individual packages. * fix: propagate user ssr.external into RSC and SSR environments Vite 6+ treats `ssr.*` config as sugar for `environments.ssr.*` only — it does NOT propagate to custom environments like `rsc`. This means packages listed in `ssr.external` (e.g. better-sqlite3) were still being transformed by Vite in the RSC environment, breaking native addon resolution via the `bindings` package. Read user's `ssr.external` array and merge it into both `environments.rsc.resolve.external` and `environments.ssr.resolve.external` so native addons are properly externalized from all server environments. Fixes CI failures in better-auth ecosystem tests on Linux where the bindings package's stack trace introspection fails when the native module is transformed by Vite. * fix: address review comments on node-modules CSS SSR crash fix - Fix wrong repo URL in test comment (nicepkg/vinext -> cloudflare/vinext) - Propagate ssr.external: true into RSC and SSR environments correctly - Move fake test packages from committed node_modules to __test_packages__ with file: protocol dependencies, removing fragile force-tracked files - Add CSS module (fake-css-module-lib) coverage to Pages Router test - Narrow Pages Router test symlinks to only required packages * fix: address bonk review comments - Update stale comment on top-level ssr block to reflect both React externalization and noExternal: true behavior; document that user ssr.noExternal is intentionally superseded by vinext's setting - Remove now-redundant noExternal: ['better-auth'] from better-auth fixture (vinext's blanket noExternal: true already covers it) - Merge Pages Router test's two separate 'it' blocks (both hit same URL) and add missing fake-css-module-rendered assertion for .module.css - Guard symlink .catch() to only swallow EEXIST errors, not all failures - Add comment explaining appDir: tmpDir usage in Pages Router test --------- Co-authored-by: James <james@eli.cx>