Repository navigation
react: answer requests from local files with routes - #6
Merged
Merged
Conversation
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>
Contributor
Author
|
New failure in post-merge full tests: workflow Newly failing:
Please fix. See logs: |
Contributor
Author
|
Post-merge failure is not caused by this PR: the same code passed on the PR run.
|
Merged
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
opened from existing branch
agent/sindresorhus/react-route-files@abc04beeb17e, which the agent did not pushAdds a
routesoption to@vcase/reactso 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.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 fromcontentType, else the extension offile, else the extension of the URL path. Every response getsaccess-control-allow-origin: *. Validation checks that the file exists, that exactly one offile/bodyis set, and theurlandstatustypes.render.ts: routes are checked first in the existingpage.routehandler. Unmatched off-origin requests are still blocked and still fail the variant.config.ts:routesis validated when the config loads, socheck/scanalso fail on a bad route.test/routes.test.tscover matching, content-type inference, validation and compilation.docs/design.mdnetwork note are updated.samples/react:theme.cssnow loads Space Grotesk fromhttps://fonts.vcase.invalid/…first, with the existing localurl()as a fallback. Two routes invcase.config.mjsserve the same.ttffiles, 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.