From d47fecf4d43a103c03650c3e5817ea12acc74662 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 23:03:26 +0000 Subject: [PATCH 1/2] fix: don't require @funstack/router for apps without file-system routing Since 1.3.2, `#rsc-client` re-exported `FsRouteSlot`, which imports `@funstack/router`. That entry is loaded by every app, so apps without the optional router peer dependency crashed the dev server and failed the production build with MISSING_EXPORT. Move `FsRouteSlot` to a separate `#rsc-client/fs-routes` client entry that only the file-system routing code imports, and add a test that keeps `#rsc-client` free of `@funstack/router` imports. Fixes #203 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KZB12ayvFAT9YQxFuKiEPX --- packages/static/package.json | 4 ++ .../src/entries/rsc-client-fs-routes.ts | 6 ++ packages/static/src/fs-routes/entries.tsx | 2 +- packages/static/src/fs-routes/runtime.tsx | 2 +- packages/static/src/fs-routes/slot.ts | 2 +- packages/static/src/rsc-client/entry.test.ts | 55 +++++++++++++++++++ packages/static/src/rsc-client/entry.ts | 1 - 7 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 packages/static/src/entries/rsc-client-fs-routes.ts create mode 100644 packages/static/src/rsc-client/entry.test.ts diff --git a/packages/static/package.json b/packages/static/package.json index b471e01..c60c983 100644 --- a/packages/static/package.json +++ b/packages/static/package.json @@ -45,6 +45,10 @@ "#rsc-client": { "types": "./src/entries/rsc-client.ts", "default": "./dist/entries/rsc-client.mjs" + }, + "#rsc-client/fs-routes": { + "types": "./src/entries/rsc-client-fs-routes.ts", + "default": "./dist/entries/rsc-client-fs-routes.mjs" } }, "files": [ diff --git a/packages/static/src/entries/rsc-client-fs-routes.ts b/packages/static/src/entries/rsc-client-fs-routes.ts new file mode 100644 index 0000000..7a06b76 --- /dev/null +++ b/packages/static/src/entries/rsc-client-fs-routes.ts @@ -0,0 +1,6 @@ +"use client"; + +// Kept separate from `#rsc-client` because it depends on `@funstack/router`, +// an optional peer dependency. Only file-system routing imports this entry, so +// apps that don't use it never load the router (#203). +export { FsRouteSlot } from "../rsc-client/fsRouteSlot"; diff --git a/packages/static/src/fs-routes/entries.tsx b/packages/static/src/fs-routes/entries.tsx index c446d95..0d06de4 100644 --- a/packages/static/src/fs-routes/entries.tsx +++ b/packages/static/src/fs-routes/entries.tsx @@ -1,4 +1,4 @@ -import { FsRouteSlot } from "#rsc-client"; +import { FsRouteSlot } from "#rsc-client/fs-routes"; import { deferRegistry, registerDeferredPayload, diff --git a/packages/static/src/fs-routes/runtime.tsx b/packages/static/src/fs-routes/runtime.tsx index 9a5cd61..a091bc1 100644 --- a/packages/static/src/fs-routes/runtime.tsx +++ b/packages/static/src/fs-routes/runtime.tsx @@ -116,7 +116,7 @@ export interface FsRoutesRuntimeHost { /** * The client component standing in for Server Component route nodes, * resolving the chunk for the current match's params. A client reference - * to `FsRouteSlot` from `#rsc-client` in the real host. + * to `FsRouteSlot` from `#rsc-client/fs-routes` in the real host. */ RouteSlot: ComponentType; } diff --git a/packages/static/src/fs-routes/slot.ts b/packages/static/src/fs-routes/slot.ts index 4031288..fc0fd7d 100644 --- a/packages/static/src/fs-routes/slot.ts +++ b/packages/static/src/fs-routes/slot.ts @@ -2,7 +2,7 @@ import type { ReactNode } from "react"; import type { FsRouteObject } from "./types"; /** - * Props of the internal client component (`FsRouteSlot` in `#rsc-client`) + * Props of the internal client component (`FsRouteSlot` in `#rsc-client/fs-routes`) * that stands in for a Server Component page or layout in the route * definitions. All props are RSC-serializable so the slot can be baked into * each page's payload. diff --git a/packages/static/src/rsc-client/entry.test.ts b/packages/static/src/rsc-client/entry.test.ts new file mode 100644 index 0000000..e4cc305 --- /dev/null +++ b/packages/static/src/rsc-client/entry.test.ts @@ -0,0 +1,55 @@ +import fs from "node:fs"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; + +const srcDir = path.resolve(import.meta.dirname, ".."); + +/** + * Collects the bare (package) specifiers reachable through static imports + * and re-exports from `entry`, following relative imports within `src/`. + */ +function collectPackageImports(entry: string): Set { + const packages = new Set(); + const visited = new Set(); + const queue = [entry]; + while (queue.length > 0) { + const file = queue.pop()!; + if (visited.has(file)) continue; + visited.add(file); + const code = fs.readFileSync(file, "utf-8"); + for (const match of code.matchAll( + /^\s*(?:import|export)\b[^;]*?\bfrom\s*["']([^"']+)["']|^\s*import\s*["']([^"']+)["']/gm, + )) { + const specifier = match[1] ?? match[2]!; + if (!specifier.startsWith(".")) { + packages.add(specifier); + continue; + } + const base = path.resolve(path.dirname(file), specifier); + const resolved = ["", ".ts", ".tsx", "/index.ts", "/index.tsx"] + .map((ext) => base + ext) + .find((candidate) => + fs.statSync(candidate, { throwIfNoEntry: false })?.isFile(), + ); + if (resolved === undefined) { + throw new Error(`Cannot resolve ${specifier} from ${file}`); + } + queue.push(resolved); + } + } + return packages; +} + +describe("#rsc-client entry", () => { + // `#rsc-client` is loaded by every app (dev server and build), so it must + // not depend on the optional `@funstack/router` peer dependency (#203). + it("does not import @funstack/router", () => { + const packages = collectPackageImports( + path.join(srcDir, "entries/rsc-client.ts"), + ); + expect(packages.has("react")).toBe(true); + expect( + [...packages].filter((p) => p.startsWith("@funstack/router")), + ).toEqual([]); + }); +}); diff --git a/packages/static/src/rsc-client/entry.ts b/packages/static/src/rsc-client/entry.ts index 0ac8f96..4c53ccf 100644 --- a/packages/static/src/rsc-client/entry.ts +++ b/packages/static/src/rsc-client/entry.ts @@ -1,4 +1,3 @@ "use client"; export { RegistryContext, DeferredComponent } from "./clientWrapper"; -export { FsRouteSlot } from "./fsRouteSlot"; From e6c850d282a64d05743d7acdb74e4eee392a485c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 23:22:50 +0000 Subject: [PATCH 2/2] test: add e2e fixture without @funstack/router Replace the import-graph unit test with an e2e fixture that does not install the optional `@funstack/router` peer dependency, run against both the production build and the dev server. Within the workspace, the symlinked `@funstack/static` would still find the router in its own devDependencies, so the fixture's Vite config makes `@funstack/router` unresolvable, as in an app that never installed it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KZB12ayvFAT9YQxFuKiEPX --- .../static/e2e/fixture-no-router/package.json | 14 +++++ .../static/e2e/fixture-no-router/src/App.tsx | 13 +++++ .../e2e/fixture-no-router/src/Counter.tsx | 19 +++++++ .../fixture-no-router/src/DeferredSection.tsx | 3 + .../static/e2e/fixture-no-router/src/root.tsx | 11 ++++ .../e2e/fixture-no-router/vite.config.ts | 35 ++++++++++++ packages/static/e2e/playwright-dev.config.ts | 14 +++++ packages/static/e2e/playwright.config.ts | 15 +++++ .../static/e2e/tests-dev/no-router.spec.ts | 28 ++++++++++ packages/static/e2e/tests/no-router.spec.ts | 28 ++++++++++ packages/static/src/rsc-client/entry.test.ts | 55 ------------------- pnpm-lock.yaml | 24 ++++++++ pnpm-workspace.yaml | 1 + 13 files changed, 205 insertions(+), 55 deletions(-) create mode 100644 packages/static/e2e/fixture-no-router/package.json create mode 100644 packages/static/e2e/fixture-no-router/src/App.tsx create mode 100644 packages/static/e2e/fixture-no-router/src/Counter.tsx create mode 100644 packages/static/e2e/fixture-no-router/src/DeferredSection.tsx create mode 100644 packages/static/e2e/fixture-no-router/src/root.tsx create mode 100644 packages/static/e2e/fixture-no-router/vite.config.ts create mode 100644 packages/static/e2e/tests-dev/no-router.spec.ts create mode 100644 packages/static/e2e/tests/no-router.spec.ts delete mode 100644 packages/static/src/rsc-client/entry.test.ts diff --git a/packages/static/e2e/fixture-no-router/package.json b/packages/static/e2e/fixture-no-router/package.json new file mode 100644 index 0000000..5526922 --- /dev/null +++ b/packages/static/e2e/fixture-no-router/package.json @@ -0,0 +1,14 @@ +{ + "name": "e2e-fixture-no-router", + "private": true, + "type": "module", + "devDependencies": { + "@funstack/static": "workspace:*", + "@types/react": "^19.3.0", + "@types/react-dom": "^19.3.0", + "@vitejs/plugin-react": "catalog:", + "react": "catalog:", + "react-dom": "catalog:", + "vite": "catalog:" + } +} diff --git a/packages/static/e2e/fixture-no-router/src/App.tsx b/packages/static/e2e/fixture-no-router/src/App.tsx new file mode 100644 index 0000000..8adb9e4 --- /dev/null +++ b/packages/static/e2e/fixture-no-router/src/App.tsx @@ -0,0 +1,13 @@ +import { defer } from "@funstack/static/entries/rsc"; +import { Counter } from "./Counter"; +import DeferredSection from "./DeferredSection"; + +export default function App() { + return ( +
+

No Router App

+ + {defer(, { name: "DeferredSection" })} +
+ ); +} diff --git a/packages/static/e2e/fixture-no-router/src/Counter.tsx b/packages/static/e2e/fixture-no-router/src/Counter.tsx new file mode 100644 index 0000000..456b0f7 --- /dev/null +++ b/packages/static/e2e/fixture-no-router/src/Counter.tsx @@ -0,0 +1,19 @@ +"use client"; +import { useEffect, useState } from "react"; + +export function Counter() { + const [count, setCount] = useState(0); + const [hydrated, setHydrated] = useState(false); + useEffect(() => { + setHydrated(true); + }, []); + return ( + + ); +} diff --git a/packages/static/e2e/fixture-no-router/src/DeferredSection.tsx b/packages/static/e2e/fixture-no-router/src/DeferredSection.tsx new file mode 100644 index 0000000..b183f0c --- /dev/null +++ b/packages/static/e2e/fixture-no-router/src/DeferredSection.tsx @@ -0,0 +1,3 @@ +export default function DeferredSection() { + return

Deferred section content

; +} diff --git a/packages/static/e2e/fixture-no-router/src/root.tsx b/packages/static/e2e/fixture-no-router/src/root.tsx new file mode 100644 index 0000000..075d0aa --- /dev/null +++ b/packages/static/e2e/fixture-no-router/src/root.tsx @@ -0,0 +1,11 @@ +export default function Root({ children }: { children: React.ReactNode }) { + return ( + + + + No Router Fixture + + {children} + + ); +} diff --git a/packages/static/e2e/fixture-no-router/vite.config.ts b/packages/static/e2e/fixture-no-router/vite.config.ts new file mode 100644 index 0000000..8541724 --- /dev/null +++ b/packages/static/e2e/fixture-no-router/vite.config.ts @@ -0,0 +1,35 @@ +import funstackStatic from "@funstack/static"; +import react from "@vitejs/plugin-react"; +import { defineConfig, type Plugin } from "vite"; + +/** + * This fixture does not install the optional `@funstack/router` peer + * dependency (#203). Inside this workspace, though, `@funstack/static` is + * symlinked and would still find the router in its own devDependencies, so + * make it unresolvable the way it is in an app that never installed it. + */ +function withoutFunstackRouter(): Plugin { + return { + name: "e2e:without-funstack-router", + enforce: "pre", + resolveId(id) { + if (id === "@funstack/router" || id.startsWith("@funstack/router/")) { + this.error( + `"${id}" is not installed in this fixture. Apps that don't use file-system routing must work without it.`, + ); + } + }, + }; +} + +export default defineConfig({ + plugins: [ + withoutFunstackRouter(), + funstackStatic({ + root: "./src/root.tsx", + app: "./src/App.tsx", + ssr: true, + }), + react(), + ], +}); diff --git a/packages/static/e2e/playwright-dev.config.ts b/packages/static/e2e/playwright-dev.config.ts index 3865eca..ebf2d86 100644 --- a/packages/static/e2e/playwright-dev.config.ts +++ b/packages/static/e2e/playwright-dev.config.ts @@ -53,6 +53,14 @@ export default defineConfig({ }, testMatch: /\/fs-routing-mpa\.spec\.ts$/, }, + { + name: "no-router-dev", + use: { + ...devices["Desktop Chrome"], + baseURL: "http://localhost:4184", + }, + testMatch: /\/no-router\.spec\.ts$/, + }, ], webServer: [ @@ -89,5 +97,11 @@ export default defineConfig({ reuseExistingServer: !process.env.CI, timeout: 120000, }, + { + command: "cd fixture-no-router && pnpm vite dev --port 4184 --strictPort", + url: "http://localhost:4184/@vite/client", + reuseExistingServer: !process.env.CI, + timeout: 120000, + }, ], }); diff --git a/packages/static/e2e/playwright.config.ts b/packages/static/e2e/playwright.config.ts index 47c86f8..d5f00e8 100644 --- a/packages/static/e2e/playwright.config.ts +++ b/packages/static/e2e/playwright.config.ts @@ -58,6 +58,14 @@ export default defineConfig({ name: "render-error", testMatch: /\/render-error\.spec\.ts$/, }, + { + name: "no-router", + use: { + ...devices["Desktop Chrome"], + baseURL: "http://localhost:4183", + }, + testMatch: /\/no-router\.spec\.ts$/, + }, ], webServer: [ @@ -96,5 +104,12 @@ export default defineConfig({ reuseExistingServer: !process.env.CI, timeout: 120000, }, + { + command: + "cd fixture-no-router && pnpm vite build && pnpm dlx serve -p 4183 dist/public", + url: "http://localhost:4183", + reuseExistingServer: !process.env.CI, + timeout: 120000, + }, ], }); diff --git a/packages/static/e2e/tests-dev/no-router.spec.ts b/packages/static/e2e/tests-dev/no-router.spec.ts new file mode 100644 index 0000000..a12959b --- /dev/null +++ b/packages/static/e2e/tests-dev/no-router.spec.ts @@ -0,0 +1,28 @@ +import { expect, test } from "@playwright/test"; + +// The fixture does not install the optional `@funstack/router` peer +// dependency (#203). +test.describe("App without @funstack/router", () => { + test("renders, loads deferred content and hydrates", async ({ page }) => { + const errors: string[] = []; + page.on("pageerror", (error) => { + errors.push(error.message); + }); + + const response = await page.goto("/"); + expect(response?.status()).toBe(200); + + await expect(page.locator("h1")).toHaveText("No Router App"); + await expect(page.getByTestId("deferred-section")).toHaveText( + "Deferred section content", + ); + + // The button is server-rendered, so wait for hydration before clicking. + const counter = page.getByTestId("counter"); + await expect(counter).toHaveAttribute("data-hydrated", "true"); + await counter.click(); + await expect(counter).toHaveText("Count: 1"); + + expect(errors).toEqual([]); + }); +}); diff --git a/packages/static/e2e/tests/no-router.spec.ts b/packages/static/e2e/tests/no-router.spec.ts new file mode 100644 index 0000000..a12959b --- /dev/null +++ b/packages/static/e2e/tests/no-router.spec.ts @@ -0,0 +1,28 @@ +import { expect, test } from "@playwright/test"; + +// The fixture does not install the optional `@funstack/router` peer +// dependency (#203). +test.describe("App without @funstack/router", () => { + test("renders, loads deferred content and hydrates", async ({ page }) => { + const errors: string[] = []; + page.on("pageerror", (error) => { + errors.push(error.message); + }); + + const response = await page.goto("/"); + expect(response?.status()).toBe(200); + + await expect(page.locator("h1")).toHaveText("No Router App"); + await expect(page.getByTestId("deferred-section")).toHaveText( + "Deferred section content", + ); + + // The button is server-rendered, so wait for hydration before clicking. + const counter = page.getByTestId("counter"); + await expect(counter).toHaveAttribute("data-hydrated", "true"); + await counter.click(); + await expect(counter).toHaveText("Count: 1"); + + expect(errors).toEqual([]); + }); +}); diff --git a/packages/static/src/rsc-client/entry.test.ts b/packages/static/src/rsc-client/entry.test.ts deleted file mode 100644 index e4cc305..0000000 --- a/packages/static/src/rsc-client/entry.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -import fs from "node:fs"; -import path from "node:path"; -import { describe, expect, it } from "vitest"; - -const srcDir = path.resolve(import.meta.dirname, ".."); - -/** - * Collects the bare (package) specifiers reachable through static imports - * and re-exports from `entry`, following relative imports within `src/`. - */ -function collectPackageImports(entry: string): Set { - const packages = new Set(); - const visited = new Set(); - const queue = [entry]; - while (queue.length > 0) { - const file = queue.pop()!; - if (visited.has(file)) continue; - visited.add(file); - const code = fs.readFileSync(file, "utf-8"); - for (const match of code.matchAll( - /^\s*(?:import|export)\b[^;]*?\bfrom\s*["']([^"']+)["']|^\s*import\s*["']([^"']+)["']/gm, - )) { - const specifier = match[1] ?? match[2]!; - if (!specifier.startsWith(".")) { - packages.add(specifier); - continue; - } - const base = path.resolve(path.dirname(file), specifier); - const resolved = ["", ".ts", ".tsx", "/index.ts", "/index.tsx"] - .map((ext) => base + ext) - .find((candidate) => - fs.statSync(candidate, { throwIfNoEntry: false })?.isFile(), - ); - if (resolved === undefined) { - throw new Error(`Cannot resolve ${specifier} from ${file}`); - } - queue.push(resolved); - } - } - return packages; -} - -describe("#rsc-client entry", () => { - // `#rsc-client` is loaded by every app (dev server and build), so it must - // not depend on the optional `@funstack/router` peer dependency (#203). - it("does not import @funstack/router", () => { - const packages = collectPackageImports( - path.join(srcDir, "entries/rsc-client.ts"), - ); - expect(packages.has("react")).toBe(true); - expect( - [...packages].filter((p) => p.startsWith("@funstack/router")), - ).toEqual([]); - }); -}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75c1485..569cb2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -338,6 +338,30 @@ importers: specifier: 'catalog:' version: 8.3.8(@types/node@26.6.6)(esbuild@0.28.2)(terser@5.47.1)(tsx@4.21.0) + packages/static/e2e/fixture-no-router: + devDependencies: + '@funstack/static': + specifier: workspace:* + version: link:../.. + '@types/react': + specifier: ^19.3.0 + version: 19.3.0 + '@types/react-dom': + specifier: ^19.3.0 + version: 19.3.0(@types/react@19.3.0) + '@vitejs/plugin-react': + specifier: 'catalog:' + version: 6.3.0(vite@8.3.8(@types/node@26.6.6)(esbuild@0.28.2)(terser@5.47.1)(tsx@4.21.0)) + react: + specifier: 'catalog:' + version: 19.3.1 + react-dom: + specifier: 'catalog:' + version: 19.3.1(react@19.3.1) + vite: + specifier: 'catalog:' + version: 8.3.8(@types/node@26.6.6)(esbuild@0.28.2)(terser@5.47.1)(tsx@4.21.0) + packages/static/e2e/fixture-render-error: devDependencies: '@funstack/static': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index c87dfec..257ad7f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -6,6 +6,7 @@ packages: - packages/static/e2e/fixture-fs-routing - packages/static/e2e/fixture-fs-routing-mpa - packages/static/e2e/fixture-render-error + - packages/static/e2e/fixture-no-router catalog: "@types/node": ^26.6.6