-
-
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
fix(routing): emit error for forbidden rewrite #12339
Conversation
🦋 Changeset detectedLatest commit: db29dd4 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 |
6378fce
to
e4cf625
Compare
Question: does this happen only with With the new |
Couldn't it just be supported instead of being forbidden? |
Not at this time, because as you said it's the adapter that helps with that (Cloudflare and Node.js), but the rewrite code is runtime agnostic, so we can't easily implement this as bugfix without providing an adapter feature for this use case. We can definitely support this via adapters, with some architectural changes, but that's definitely a feature, and it requires adapters to have a role in this. |
@sarah11918 I am not really sure to be honest, I need to investigate |
Just a note that I'll want to look over docs after we know whether we need to specifically say |
@sarah11918 I looked at it, and this change affects only |
858d0e5
to
047e6de
Compare
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.
Thanks @ematipico ! Had just wanted to make sure we needed the extra bit of wording (and that everything is fine in static
mode) to know exactly what we needed to say! 🙌
Just fixed some tiny typos and had a thought about the error name for your consideration!
* | ||
*/ | ||
export const ForbiddenRewrite = { | ||
name: 'ForbiddenRewrite', |
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.
Just noting that there may eventually be other kinds of "forbidden" rewrites, so not sure whether you want to add more context like ForbiddenRewriteToStatic
or something like that?
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'd prefer not. The kind of error would be the same, but we can customise the message based on the situation.
// This is a case where the user tries to rewrite from a SSR route to a prerendered route (SSG). | ||
// This case isn't valid because when building for SSR, the prerendered route disappears from the server output because it becomes an HTML file, | ||
// so Astro can't retrieve it from the emitted manifest. | ||
if ( |
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.
Is there a way we could avoid the duplication across all the pipelines?
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.
It really depends on how you want to avoid the duplication. We can put the check in one single function, but I think the error should be thrown where we consume the check. What do you have in mind?
Co-authored-by: Reuben Tier <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Bjorn Lu <[email protected]> Co-authored-by: Florian Lefebvre <[email protected]> Co-authored-by: Reuben Tier <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
9328687
to
db29dd4
Compare
Changes
Closes PLT-2607
Closes #12336
Even though the issue was reported for Astro v4, unfortunately, we can't fix it because the
prerender
field doesn't change there, and we fixed that issue in v5.This PR forbids to rewrite a SSR route with a SSG route, when using the
server
output. That's because when the SSG routes are built, they aren't part of the server output, and they are emitted as static files. Static files are served by the host, and the Astro runtime can't retrieve them at runtime during the rewriting process. This results in a runtime error at the moment.Because of that, I decided to simulate a similar behaviour and throw an error, with some information.
Testing
I added a new test case
Docs
I will probably send a PR to explain this limitation.