Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/static/e2e/fixture-no-router/package.json
Original file line number Diff line number Diff line change
@@ -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:"
}
}
13 changes: 13 additions & 0 deletions packages/static/e2e/fixture-no-router/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defer } from "@funstack/static/entries/rsc";
import { Counter } from "./Counter";
import DeferredSection from "./DeferredSection";

export default function App() {
return (
<main>
<h1>No Router App</h1>
<Counter />
{defer(<DeferredSection />, { name: "DeferredSection" })}
</main>
);
}
19 changes: 19 additions & 0 deletions packages/static/e2e/fixture-no-router/src/Counter.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<button
data-testid="counter"
data-hydrated={hydrated}
onClick={() => setCount((c) => c + 1)}
>
Count: {count}
</button>
);
}
3 changes: 3 additions & 0 deletions packages/static/e2e/fixture-no-router/src/DeferredSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function DeferredSection() {
return <p data-testid="deferred-section">Deferred section content</p>;
}
11 changes: 11 additions & 0 deletions packages/static/e2e/fixture-no-router/src/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="UTF-8" />
<title>No Router Fixture</title>
</head>
<body>{children}</body>
</html>
);
}
35 changes: 35 additions & 0 deletions packages/static/e2e/fixture-no-router/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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(),
],
});
14 changes: 14 additions & 0 deletions packages/static/e2e/playwright-dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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,
},
],
});
15 changes: 15 additions & 0 deletions packages/static/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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,
},
],
});
28 changes: 28 additions & 0 deletions packages/static/e2e/tests-dev/no-router.spec.ts
Original file line number Diff line number Diff line change
@@ -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([]);
});
});
28 changes: 28 additions & 0 deletions packages/static/e2e/tests/no-router.spec.ts
Original file line number Diff line number Diff line change
@@ -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([]);
});
});
4 changes: 4 additions & 0 deletions packages/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 6 additions & 0 deletions packages/static/src/entries/rsc-client-fs-routes.ts
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 1 addition & 1 deletion packages/static/src/fs-routes/entries.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FsRouteSlot } from "#rsc-client";
import { FsRouteSlot } from "#rsc-client/fs-routes";
import {
deferRegistry,
registerDeferredPayload,
Expand Down
2 changes: 1 addition & 1 deletion packages/static/src/fs-routes/runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FsRouteSlotProps>;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/static/src/fs-routes/slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion packages/static/src/rsc-client/entry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use client";

export { RegistryContext, DeferredComponent } from "./clientWrapper";
export { FsRouteSlot } from "./fsRouteSlot";
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down