Repository navigation
Use React Router framework mode + SPA mode - #3400
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| export const clientLoader = projectLayoutLoader | ||
| export async function clientLoader({ params }: Route.ClientLoaderArgs) { | ||
| return projectLayoutLoader(params) | ||
| } |
There was a problem hiding this comment.
This is so we can check the params against Route.ClientLoaderArgs
| export const handle = makeCrumb( | ||
| (p) => p.antiAffinityGroup!, | ||
| (p) => pb.antiAffinityGroup(getAntiAffinityGroupSelector(p)) | ||
| ) |
There was a problem hiding this comment.
I have a followup PR that typechecks these handles against the route params, avoiding the !, but it's gnarly and hacky TypeScript so I wanted to keep it separate.
|
Visual regression test against main if not done already would be a good extra validation. But I am very excited to get hot reload again! |
While doing #3400, I realized I wanted a way to test the CSP from Nexus against our actual production bundle. I decide that because CSP is enforced in the browser, we don't need Nexus for this at all, we just need the CSP string. So all we have to do is use regex to extract that from the pinned Omicron commit, and then we can test the CSP with `vite preview` and a Playwright test. I was able to confirm the test fails when it's supposed to: on the #3400 branch, if I comment out the step that moves React Router's inline bootstrap scripts into separate files, the app never renders and the test fails with the browser's CSP errors: ``` Error: expect(received).toEqual(expected) // deep equality - Array [] + Array [ + "Executing inline script violates the following Content Security Policy directive 'default-src 'self''. [...] The action has been blocked.", + [3 more of those] + "CSP violation: script-src-elem inline", + "CSP violation: script-src-elem inline", ``` Once I had that in place, I thought about what else we might want to test about the contract with Nexus, and I remembered that I have sometimes forgotten to add a new route handler on the Nexus side when we added a new top-level route prefix in the console. So I added a test that similarly extracts the console routes from Nexus and makes sure all the client-side routes are covered by those handlers. That immediately turned up a bug (go to https://oxide.sys.r3.oxide-preview.com/images, click an image, and then refresh — 404), which is fixed in oxidecomputer/omicron#11467. So the test will fail until that is merged and omicron is bumped. This is nice and neat because #3402 pulls out the setup.
|
Visual regression test is clean, just some weirdness with timing around UUID truncation moving things by a pixel. |
|
Only problem with dropping |
|
hmm ok why not. i'll make it a PR isntead |
This reverts commit 0f66a7e.
Nothing in the repo references these packages any more. The lockfile goes from 709 to 704 entries. `tslib` and `@react-router/node` stay installed as dependencies of other packages, so for those two this only tidies `package.json`. Lint, tsc, build, and the vitest suite pass. I did not run e2e locally. - `tslib` came from the Nx generator that created the repo ([source](https://github.com/nrwl/nx/blob/313552b/packages/react/src/schematics/init/init.ts#L55-L61)), along with `importHelpers: true` in tsconfig, which tells tsc to import helpers like `__awaiter` from tslib instead of inlining them. tsc never emitted our build (that was Babel, then Vite), but with `importHelpers` on, typechecking fails with TS2354 if tslib can't be resolved and the target needs a helper, as ours did while it was es2015. #2078 raised the target to es2020 and #3075 removed `importHelpers`. It is still installed through `@peculiar/x509` and others. - `@tailwindcss/container-queries` was added in #2654 for the `@container` and `@[48rem]:` variants on the instance metrics tabs, loaded as a plugin in `tailwind.config.ts`. Tailwind 4 [has container queries built in](https://github.com/tailwindlabs/tailwindcss-container-queries/blob/7a968b3/README.md?plain=1#L1-L2), and #2910 deleted the config file that loaded the plugin but left the package. - `@tanstack/react-query-devtools` was added in #1238 to show the React Query devtools panel in dev. It was commented out in cc67cff to keep it out of screenshots, and #3400 deleted the commented-out lines. - `react-is` and `@types/react-is` also came from the Nx generator, which adds them alongside styled-components ([source](https://github.com/nrwl/nx/blob/313552b/packages/react/src/utils/styled.ts#L18-L28)) because styled-components 5 has react-is as a peer dependency. We replaced styled-components with emotion in 451bef6. `@reach/menu-button` 0.16 also had react-is as a peer dependency until #1395 replaced it with Radix, and no package in the lockfile has had one since. Nothing in the repo has ever imported react-is, so the types were never used. - `@react-router/node` was added in #3400, following the [React Router SPA guide](https://github.com/remix-run/react-router/blob/f482813/docs/how-to/spa.md#L38), which says a project needs it for the build-time render of `index.html`. Our `entry.server.tsx` uses web streams and doesn't import it, and `@react-router/dev` already depends on the exact same version, so it stays installed.
oxidecomputer/console@00cc6bf...fe921de * [fe921de7](oxidecomputer/console@fe921de7) oxidecomputer/console#3447 * [0d501853](oxidecomputer/console@0d501853) oxidecomputer/console#3440 * [f9f6fee6](oxidecomputer/console@f9f6fee6) oxidecomputer/console#3445 * [84c2b7d9](oxidecomputer/console@84c2b7d9) oxidecomputer/console#3446 * [ece52b51](oxidecomputer/console@ece52b51) oxidecomputer/console#3411 * [a67b1684](oxidecomputer/console@a67b1684) oxidecomputer/console#3444 * [e9c1e3c9](oxidecomputer/console@e9c1e3c9) oxidecomputer/console#3443 * [efc2149c](oxidecomputer/console@efc2149c) oxidecomputer/console#3442 * [3b76a1ef](oxidecomputer/console@3b76a1ef) oxidecomputer/console#3441 * [47477f2d](oxidecomputer/console@47477f2d) oxidecomputer/console#3439 * [e78bb08a](oxidecomputer/console@e78bb08a) oxidecomputer/console#3437 * [129a4a55](oxidecomputer/console@129a4a55) oxidecomputer/console#3436 * [bc4acfba](oxidecomputer/console@bc4acfba) oxidecomputer/console#3419 * [595b391c](oxidecomputer/console@595b391c) oxidecomputer/console#3431 * [3a0b5a94](oxidecomputer/console@3a0b5a94) oxidecomputer/console#3421 * [7b9d2e38](oxidecomputer/console@7b9d2e38) oxidecomputer/console#3430 * [94f1e9e0](oxidecomputer/console@94f1e9e0) oxidecomputer/console#3422 * [d8b40dfa](oxidecomputer/console@d8b40dfa) oxidecomputer/console#3428 * [12bb33ec](oxidecomputer/console@12bb33ec) oxidecomputer/console#3426 * [615ac0f2](oxidecomputer/console@615ac0f2) oxidecomputer/console#3425 * [294d7066](oxidecomputer/console@294d7066) oxidecomputer/console#3420 * [31b93cbc](oxidecomputer/console@31b93cbc) oxidecomputer/console#3418 * [d84d7104](oxidecomputer/console@d84d7104) oxidecomputer/console#3393 * [7988361e](oxidecomputer/console@7988361e) oxidecomputer/console#3412 * [bae3b7a6](oxidecomputer/console@bae3b7a6) oxidecomputer/console#3400 * [b9503394](oxidecomputer/console@b9503394) oxidecomputer/console#3409 * [5147e774](oxidecomputer/console@5147e774) oxidecomputer/console#3408 * [16b3d164](oxidecomputer/console@16b3d164) oxidecomputer/console#3407 * [a64d548d](oxidecomputer/console@a64d548d) oxidecomputer/console#3406 * [df32a018](oxidecomputer/console@df32a018) oxidecomputer/console#3405 * [1cd46185](oxidecomputer/console@1cd46185) oxidecomputer/console#3403 * [f4684104](oxidecomputer/console@f4684104) oxidecomputer/console#3402
https://reactrouter.com/how-to/spa
The behavior and basic architecture of the console is unchanged: we're still a fully static SPA served by Nexus. This PR just changes how our route files are hooked up to the router. The point of this is to
Hot reloading was broken because our route modules export
clientLoaderandhandlenext to the component. React Fast Refresh only accepts modules whose exports are all components, so editing any page triggered a full reload. The framework's Vite plugin knows about route exports and hot-updates them itself (RR docs on supported exports). We could have fixed hot reloading without using framework mode, but it would have be just as long of a PR and we wouldn't get the typegen.Changes
app/routes.tsx(JSX<Route>tree withlazy+convert) toapp/routes.tsusing the framework route helpers. Routes that had an inlinehandle, an index redirect, or a reused component with a different crumb now point at small modules inapp/routes/, since in framework mode a route'shandleand loader have to come from the module.clientLoaderuses the generatedRoute.ClientLoaderArgsand destructures the keys it needs instead of calling agetXSelectorhelper. We destructure these params on purpose in order to pass on only what we need:paramsalso holds child-route params, and two query builders (routeList,instanceNetworkInterfaceList) pass their argument through as the API query, so passingparamswhole would add e.g.route=xto the request and the cache key and break the prefetch. AGENTS.md has a line about this.pbhelpers use typedhref(), so paths and params are checked against the route config. We could in theory ditchpbaltogether and just inline the paths, but I think it's still worth keeping.index.htmlis gone.root.tsxrenders the document, andnpm run buildprerenders it at build time. This requires binding a localhost port during the build (noted in AGENTS.md for sandboxed agents).buildEndstep (tools/externalize-spa-scripts.ts) moves each one into a hashed file underassets/, andentry.client.tsxempties those tags back out after they run so hydration sees the DOM shape React Router expects.dist/tobuild/client/. React Router always writes the client build to<buildDirectory>/client, so CI, Vercel,npm run preview, and the docs now point there. The tarball is built from inside that directory, so the layout Nexus sees is unchanged. Sourcemaps still ship, same as main.routeDiscovery: 'initial': by default, framework mode uses lazy route discovery. The initial page load gets only the route manifest entries for the current URL, and the client fetches the rest from a/__manifestserver endpoint as you navigate. That's an optimization for apps with a lot of routes. We don't have that many, and Nexus doesn't serve that endpoint anyway, soinitialmode puts the whole manifest in the initial load (see the bundle comparison below for its size).app/(plus the design system), because watched Markdown elsewhere in the repo was triggering full reloads. This drops only.shadow,.!filter, and.[commit:string], which were picked up from words inflake.nix, an e2e test, and a deno tool. This could be done separately from this PR but it was relevant here because it reduces the number events that trigger reloads.loaderexport inOxqlMetric.tsx. It was dead on main too: added in Instance Metrics using OxQL #2654, but nothing ever imported it.API_MODEerror message, which said the default ismswwhen it'snexus.How we checked it
Opus 5.5 did the following during review:
app/routes.tsagainst main'sroutes.tsxroute by route: nesting, index redirects, crumbs, IDs on reused modules, and the oldelement={null}routes. Everything matches.path-builder.spec.tsnow builds its routes from the real framework config and module handles instead of the old JSX tree.ProjectsPage.tsx, which exportsclientLoaderandhandle, with the create form open. It hot-updated without a full reload, and text typed into the form survived.theme.e2e.tscheck thattheme-init.jssets the theme before React loads. They do this by blocking the app's entry script, which is nowentry.client.tsxinstead ofmain.tsx. On main, the tests confirmed the block worked by asserting that#rootwas empty, but the framework's document has no#root. Now they wait for the blocked request to fail instead. If the entry file is renamed again, the block stops matching and the tests fail, rather than letting React load and passing without testing anything.Bundle compared with main (Nexus build)
*-client-loader-*chunks and 24*-main-*chunks, so a route's loader can start fetching before its component code arrives. About 34 more are the tiny route stubs inapp/routes/. Most are under 1 KB.splitRouteModules: falseturns splitting off if the file count is a problem.routeDiscovery: 'initial'.Known dev-only quirk
Index routes that re-export a tab's
clientLoader(vpc-index,sled-index,inventory-index,alerting-index,affinity-create) keep the old loader after you edit that tab until a full reload.Typechecking breadcrumb params against each route's params will come in a followup PR.