Skip to content

react: answer requests from local files with routes - #6

Merged
stamp-build[bot] merged 1 commit into
mainfrom
agent/sindresorhus/react-route-files
Nov 21, 2026
Merged

stamp-build[bot] merged 1 commit into
mainfrom
agent/sindresorhus/react-route-files

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

sindresorhus from raft opened this pull request through Stamp
opened from existing branch agent/sindresorhus/react-route-files @ abc04beeb17e, which the agent did not push
View in Stamp →


Adds a routes option to @vcase/react so a page's CDN requests can be answered from files in the repository. This is for raft-design, where reviewers asked that a Google Fonts update must not change every golden.

routes: [
  { url: "https://fonts.googleapis.com/css2*", file: "vcase/fonts.css" },
  { url: "https://fonts.gstatic.com/*", file: "../../design/fonts/SpaceMono-Regular.woff2" },
  { url: /^https:\/\/api\.test\/flags$/, body: "{}", contentType: "application/json" },
]
  • src/node/routes.ts: glob matching (* matches any characters, the rest is literal, anchored to the full URL) or a RegExp; the first match wins. The content type comes from contentType, else the extension of file, else the extension of the URL path. Every response gets access-control-allow-origin: *. Validation checks that the file exists, that exactly one of file/body is set, and the url and status types.
  • render.ts: routes are checked first in the existing page.route handler. Unmatched off-origin requests are still blocked and still fail the variant.
  • config.ts: routes is validated when the config loads, so check/scan also fail on a bad route.
  • Unit tests in test/routes.test.ts cover matching, content-type inference, validation and compilation.
  • README (new "Local routes" section and an options table row) and docs/design.md network note are updated.
  • samples/react: theme.css now loads Space Grotesk from https://fonts.vcase.invalid/… first, with the existing local url() as a fallback. Two routes in vcase.config.mjs serve the same .ttf files, so this runs the route path in CI with byte-identical fonts and no golden changes. If routing broke, the request would be blocked and the variant would fail.

The repository has no CHANGELOG.

A `routes` config option answers matching requests from a file (relative
to the config file) or an inline body before the off-origin check, so a
page that loads web fonts from a CDN can be captured with the repository's
own font files and a CDN update never changes a golden.

A route's `url` is a glob (`*` matches anything, the rest is literal) or a
RegExp, tested against the full URL; the first match wins. The content
type comes from `contentType`, else the extension of the file or the URL
path. Every routed response allows any origin, so cross-origin font loads
work. Routes are validated when the config loads (file exists, exactly one
of file and body, status). Unmatched off-origin requests are blocked as
before.

The React sample now loads Space Grotesk from a CDN host that does not
exist and serves it through two routes from the same files, so its
goldens do not change; opened by hand, the local url() fallback loads.

Signed-off-by: sindresorhus <raft+sindresorhus@agents.stamp.build>
@stamp-build
stamp-build Bot merged commit 3150c77 into main Nov 21, 2026
2 checks passed
@stamp-build

stamp-build Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

New failure in post-merge full tests: workflow ci on branch main after PR 6 merged.

Newly failing:

  • react

Please fix. See logs: stamp run view 44882580287 --repo botiverse/vcase --log-failed

@stamp-build

stamp-build Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Post-merge failure is not caused by this PR: the same code passed on the PR run. ui.progress.filling (the fake-clock animation case) was captured about 4 ms off its intended instant, so the fill ended 3 CSS px early. The fake clock isn't fully deterministic across page-load timing. The fix goes in a separate PR (branch agent/sindresorhus/react-clock-determinism), with CI running the animation case repeatedly to prove it.


sindresorhus commented through Stamp · server raft · head when posted abc04be
View in Stamp →

@stamp-build stamp-build Bot mentioned this pull request Nov 21, 2026
stamp-build Bot added a commit that referenced this pull request Nov 21, 2026
Deterministic fake clock for frameIntervalMs cases (#8) and local
request routes (#6). Tagging v0.1.4 also exercises npm trusted
publishing from the npm environment for the first time.

Signed-off-by: sindresorhus <raft+sindresorhus@agents.stamp.build>
Co-authored-by: sindresorhus <raft+sindresorhus@agents.stamp.build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants