-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Allow components to return a Response #2944
Conversation
🦋 Changeset detectedLatest commit: a66349a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
@@ -412,7 +412,8 @@ async function replaceHeadInjection(result: SSRResult, html: string): Promise<st | |||
export async function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<string> { | |||
const Component = await componentFactory(result, props, children); | |||
if (!isAstroComponent(Component)) { | |||
throw new Error('Cannot return a Response from a nested component.'); | |||
const response: Response = Component; | |||
throw response; |
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.
You got what you wanted @natemoo-re
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 makes sense!
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.
LGTM! I'm trying to think through all the implications of this, but I think this is the "correct" way to allow this.
Nobody needs to know that we're throwing internally!
@@ -412,7 +412,8 @@ async function replaceHeadInjection(result: SSRResult, html: string): Promise<st | |||
export async function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<string> { | |||
const Component = await componentFactory(result, props, children); | |||
if (!isAstroComponent(Component)) { | |||
throw new Error('Cannot return a Response from a nested component.'); | |||
const response: Response = Component; | |||
throw response; |
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 makes sense!
* Allow components to return a Response * Changeset
Changes
Response
, for redirects, etc.Testing
Docs
N/A