Skip to content

Commit

Permalink
refactor(react-server): simplify route tree utils (#338)
Browse files Browse the repository at this point in the history
Picking up some code from
- #257

Preparing for
- #337

The idea is to extract routing logic (fs route tree generation + route matching) out of react-server world, so it can be used anywhere as a pure utility. This also helps test-ability.
  • Loading branch information
hi-ogawa authored Jun 4, 2024
1 parent b9ec275 commit 85fe160
Show file tree
Hide file tree
Showing 8 changed files with 1,160 additions and 218 deletions.
8 changes: 3 additions & 5 deletions packages/react-server/examples/basic/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ testNoJs("catch-all routes @nojs", async ({ page }) => {
await testCatchallRoute(page, { js: false });
});

async function testCatchallRoute(page: Page, options: { js: boolean }) {
async function testCatchallRoute(page: Page, _options: { js: boolean }) {
await page
.getByRole("link", { name: "• /test/dynamic/catchall/static" })
.click();
Expand Down Expand Up @@ -904,10 +904,8 @@ async function testCatchallRoute(page: Page, options: { js: boolean }) {
.click();
await page.getByText("file: /test/dynamic/catchall").click();
await page.getByText('params: {"any":"x/y/w"}').click();
// state is preserved
await expect(page.getByLabel("test state")).toBeChecked({
checked: options.js,
});
// state is not preserved
await expect(page.getByLabel("test state")).not.toBeChecked();
}

test("full client route", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/src/entry/react-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
createError,
getErrorContext,
} from "../lib/error";
import { generateRouteTree, renderRouteMap } from "../lib/router";
import { generateRouteModuleTree, renderRouteMap } from "../lib/router";

const debug = createDebug("react-server:rsc");

Expand Down Expand Up @@ -147,7 +147,7 @@ function createRouter() {
eager: true,
},
);
const tree = generateRouteTree(
const tree = generateRouteModuleTree(
objectMapKeys(glob, (_v, k) => k.slice("/src/routes".length)),
);

Expand Down
Loading

0 comments on commit 85fe160

Please sign in to comment.