Skip to content

Show injected custom 404 route in dev#6940

Merged
matthewp merged 10 commits into
mainfrom
chris/6937
May 1, 2023
Merged

Show injected custom 404 route in dev#6940
matthewp merged 10 commits into
mainfrom
chris/6937

Conversation

@delucis
Copy link
Copy Markdown
Member

@delucis delucis commented Apr 28, 2023

Changes

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.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2023

🦋 Changeset detected

Latest 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

@delucis delucis changed the title Show custom 404 route in dev Show injected custom 404 route in dev Apr 28, 2023
@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Apr 28, 2023
@delucis delucis marked this pull request as draft April 28, 2023 22:38
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.
@delucis delucis marked this pull request as ready for review April 29, 2023 09:28
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));
Copy link
Copy Markdown
Member Author

@delucis delucis Apr 29, 2023

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);
Copy link
Copy Markdown
Member Author

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?

@delucis

This comment was marked as outdated.

@delucis delucis requested review from bluwy and matthewp April 30, 2023 08:22
@matthewp matthewp merged commit a98df93 into main May 1, 2023
@matthewp matthewp deleted the chris/6937 branch May 1, 2023 14:37
@astrobot-houston astrobot-houston mentioned this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom 404 page injected using injectRoute not used

2 participants