-
-
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
Switch app.render
signature
#9199
Conversation
🦋 Changeset detectedLatest commit: a756ff1 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 |
6972b25
to
585ce6f
Compare
6f0b63b
to
40b0699
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.
Code looks good! Just a few thoughts on how we roll this out and talk about it, but nothing blocking.
packages/astro/src/core/app/node.ts
Outdated
if (!(req instanceof Request)) { | ||
req = createRequestFromNodeRequest(req); | ||
} | ||
return super.render(req, routeData, locals); | ||
return super.render(req, { routeData, locals }); |
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.
Do any adapters extend from App
? They might need to be updated as well, but I guess it's not urgent since this is backwards-compatible.
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.
Only NodeApp extends from App. Cloudflare uses App as-is.
@@ -145,7 +151,23 @@ export class App { | |||
return routeData; | |||
} | |||
|
|||
async render(request: Request, routeData?: RouteData, locals?: object): Promise<Response> { | |||
async render(request: Request, options?: RenderOptions): Promise<Response> | |||
async render(request: Request, routeData?: RouteData, locals?: object): Promise<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.
Adding a /** @deprecated See https://github.com/withastro/astro/pull/9199 */
comment above the old signature would be good so that users get a hint in their editor.
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 can deprecate an overload?!
packages/astro/src/core/app/node.ts
Outdated
} | ||
} | ||
else { | ||
routeData = routeDataOrOptions as RouteData; |
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.
Should we log a deprecation warning here? Maintainers probably won't catch this change unless we have visible log.
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.
In the Integration API, the `app.render()` method of the `App` class has been simplified. | ||
|
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 would rephrase this or add a note that this change is really only relevant for adapter/integration maintainers, not a something that users of official Astro adapters need to update.
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.
Updated in the commit titled "clarify changeset".
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 we also need major changesets for @astrojs/node
and @astrojs/vercel
since they're using a new syntax that won't be compatible with previous Astro versions anymore.
packages/astro/src/core/app/node.ts
Outdated
if (!(req instanceof Request)) { | ||
req = createRequestFromNodeRequest(req); | ||
} | ||
return super.render(req, routeData, locals); | ||
return super.render(req, { routeData, locals }); |
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 we can pass this as super.render(req, routeData, locals);
like before so that the warning handling is all handled within App
, and we don't have to duplicate the validation in NodeApp
?
We can also make logRenderOptionsDeprecationWarning
private with a leading #
then.
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.
Wouldn't that make it log the warning everytime?
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'm not sure I understand. Wouldn't the duplicate validation here also log the warning everytime? As long as the consumer of NodeApp
(in this case @astrojs/node
) uses the new API form, it shouldn't log the warning.
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.
Wouldn't the duplicate validation here also log the warning everytime?
It doesn't. It only logs a warning when the old API is used.
However, if NodeApp.render in turn uses the base method in the old form, the base method will log a warning everytime no matter what form the adapter author used.
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 my initial suggestion was incorrect. I meant super.render(req, routeDataOrOptions, locals);
. Perhaps that's where the confusion is 😅
If we simply pass the arguments back to super.render
, the newer API would also be passed through.
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.
ok yeah that 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.
Looks great!
@lilnasy can you fix the conflicts so we can get this in? |
583425d
to
a756ff1
Compare
@lilnasy feel free to merge this if it's ready. or if you're waiting for a docs review? |
Yeah, it's ready to merge. I'm under the impression that docs will review 4.0 stuff at a later point (not in the next branch). |
remove warning: [deprecated] The adapter @astro-aws/adapter is using a deprecated signature of the 'app.render()' method. From Astro 4.0, locals and routeData are provided as properties on an optional object to this method. Using the old signature will cause an error in Astro 5.0. See withastro/astro#9199 for more information.
remove warning: [deprecated] The adapter @astro-aws/adapter is using a deprecated signature of the 'app.render()' method. From Astro 4.0, locals and routeData are provided as properties on an optional object to this method. Using the old signature will cause an error in Astro 5.0. See withastro/astro#9199 for more information.
* feat: update Astro render call for v4 The app.render call deprecates the third argument in favor of an object with teh routeData as a property. See withastro/astro#9199 for more information. * chore: add changeset * feat: add v3 render support * fix: resolve import issue with const file remove unused type * feat: add a safe fall-through on version parsing * Sync --------- Co-authored-by: Frank <wangfanjie@gmail.com>
Changes
app.render(request, undefined, locals)
->app.render(request, { locals })
Testing
Switched a couple of tests to use the new API, keeping two as-is that still test the current API.
Docs