Skip to content
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

fix(ssr): correctly call the middleware when rendering error pages #8200

Merged
merged 5 commits into from
Aug 25, 2023

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Aug 23, 2023

Changes

Closes #8154

This fix goes into next because it requires some infrastructure that we have there but not in main.

This PR removes the onRequest function from the "ComponentInstance", instead we move its resolution inside the pipeline. The middleware now becomes 100% detached from a page/route.

This change fits perfectly because the SSR build already creates a middleware.mjs file, and we already save the middlewareEntryPoint file.

Testing

I created a new test case.

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Aug 23, 2023

⚠️ No Changeset found

Latest commit: 4f1750f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 23, 2023
@@ -12,6 +12,5 @@ export const RedirectComponentInstance: ComponentInstance = {

export const RedirectSinglePageBuiltModule: SinglePageBuiltModule = {
page: () => Promise.resolve(RedirectComponentInstance),
onRequest: (ctx, next) => next(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see, there's no need for this stub anymore.

@@ -245,6 +250,7 @@ function buildManifest(
clientDirectives: Array.from(settings.clientDirectives),
entryModules,
assets: staticFiles.map(prefixAssetPath),
middlewareEntryPoint: internals.middlewareEntryPoint?.toString() ?? undefined,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We saved the entry point in the SSR manifest, as it was a route.

@ematipico ematipico force-pushed the fix/middleware-error-2-plt-832 branch from 5f5de60 to 1c6ad96 Compare August 23, 2023 14:50

Verified

This commit was signed with the committer’s verified signature.
jrjohnson Jon Johnson

Verified

This commit was signed with the committer’s verified signature.
jrjohnson Jon Johnson

Verified

This commit was signed with the committer’s verified signature.
jrjohnson Jon Johnson
@ematipico ematipico force-pushed the fix/middleware-error-2-plt-832 branch 2 times, most recently from c67f4c5 to 6c76466 Compare August 24, 2023 12:13
Base automatically changed from next to main August 24, 2023 14:38

Verified

This commit was signed with the committer’s verified signature.
jrjohnson Jon Johnson
@ematipico ematipico force-pushed the fix/middleware-error-2-plt-832 branch from 6c76466 to 7715cb6 Compare August 24, 2023 15:06

Verified

This commit was signed with the committer’s verified signature.
jrjohnson Jon Johnson
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.

Astro.locals, set in middleware, available on 404 page in dev mode but not in production mode
3 participants