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

Switch app.render signature #9199

Merged
merged 8 commits into from
Nov 29, 2023
Merged

Switch app.render signature #9199

merged 8 commits into from
Nov 29, 2023

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Nov 27, 2023

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

Copy link

changeset-bot bot commented Nov 27, 2023

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Nov 27, 2023
@lilnasy lilnasy force-pushed the next-app-render branch 3 times, most recently from 6972b25 to 585ce6f Compare November 27, 2023 16:15
@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Nov 27, 2023
@lilnasy lilnasy marked this pull request as ready for review November 27, 2023 17:13
Copy link
Member

@natemoo-re natemoo-re left a 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.

if (!(req instanceof Request)) {
req = createRequestFromNodeRequest(req);
}
return super.render(req, routeData, locals);
return super.render(req, { routeData, locals });
Copy link
Member

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.

Copy link
Contributor Author

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>
Copy link
Member

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.

Copy link
Contributor Author

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?!

}
}
else {
routeData = routeDataOrOptions as RouteData;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Comment on lines 5 to 6
In the Integration API, the `app.render()` method of the `App` class has been simplified.

Copy link
Member

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.

Copy link
Contributor Author

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".

Copy link
Member

@bluwy bluwy left a 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.

if (!(req instanceof Request)) {
req = createRequestFromNodeRequest(req);
}
return super.render(req, routeData, locals);
return super.render(req, { routeData, locals });
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Looks great!

@matthewp
Copy link
Contributor

@lilnasy can you fix the conflicts so we can get this in?

@bluwy
Copy link
Member

bluwy commented Nov 29, 2023

@lilnasy feel free to merge this if it's ready. or if you're waiting for a docs review?

@lilnasy
Copy link
Contributor Author

lilnasy commented Nov 29, 2023

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).

@lilnasy lilnasy merged commit 49aa215 into next Nov 29, 2023
13 checks passed
@lilnasy lilnasy deleted the next-app-render branch November 29, 2023 15:38
This was referenced Nov 29, 2023
bayssmekanique added a commit to bayssmekanique/sst that referenced this pull request Dec 18, 2023
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.
mseele added a commit to mseele/astro-aws that referenced this pull request Jan 18, 2024
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.
lukeshay pushed a commit to lukeshay/astro-aws that referenced this pull request Jan 21, 2024
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.
fwang added a commit to sst/sst that referenced this pull request Feb 5, 2024
* 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>
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) pkg: integration Related to any renderer integration (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants