-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show injected custom 404 route in dev #6940
Conversation
🦋 Changeset detectedLatest commit: 80ca780 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Dynamic catch-all routes can match against `/404/` but will then error because they’re not actually designed to handle a param of `'404'`. Testing `route` instead excludes dynamic routes (because they’ll contain dynamic segments inside square brackets). Not sure if someone might _want_ to render the 404 via a dynamic route, but we already don’t support that, so this doesn’t change anything.
return manifest.routes.find((r) => r.component.match(pattern)); | ||
function getCustom404Route(manifest: ManifestData): RouteData | undefined { | ||
const route404 = /^\/404\/?$/; | ||
return manifest.routes.find((r) => route404.test(r.route)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is safe? Previously we only supported 404.astro
, 404.md
, 404.mdx
, and 404.mdoc
as custom 404 routes. Those would all have a route
of /404
or /404/
, so are still supported. This change adds custom 404 support for src/pages/404.html
or for injectRoute({ pattern: '404', entrypoint: '...' })
in dev.
await r.done; | ||
const doc = await r.text(); | ||
expect(doc).to.match(/<h1>Custom 404<\/h1>/); | ||
expect(r.res.statusCode).to.equal(200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure whether we should expect a 404 status here or whether this request/response mock always returns 200?
Changes
injectRoute
not used #6937getCustom404Route
logic to find 404s added viainjectRoute
src/pages/404.html
, which we don’t have currently.Testing
Added a fixture + test like we have for the current custom 404 strategies and also a dev server unit test.
I also applied the same changes in a patch inside a monorepo project to test the logic when the injected route comes from a separate package.
Docs
Bug fix, no docs needed.