-
-
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
Changes from 1 commit
00f8542
f5996ea
a56bf8a
ebf2822
2f81429
5799c8d
2bad1b4
a756ff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'astro': major | ||
--- | ||
|
||
The adapter API now offers a simpler signature for rendering. The `render()` method on App now accepts an `options` object. | ||
|
||
```diff | ||
- app.render(request, undefined, locals) | ||
+ app.render(request, { locals }) | ||
``` | ||
The current signature is deprecated but will continue to function until next major version. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import type { RouteData } from '../../@types/astro.js'; | ||
import type { SerializedSSRManifest, SSRManifest } from './types.js'; | ||
import type { RenderOptions } from './index.js'; | ||
|
||
import * as fs from 'node:fs'; | ||
import { IncomingMessage } from 'node:http'; | ||
|
@@ -116,11 +117,27 @@ export class NodeApp extends App { | |
} | ||
return super.match(req); | ||
} | ||
render(req: NodeIncomingMessage | Request, routeData?: RouteData, locals?: object) { | ||
render(request: NodeIncomingMessage | Request, options?: RenderOptions): Promise<Response> | ||
render(request: NodeIncomingMessage | Request, routeData?: RouteData, locals?: object): Promise<Response> | ||
render(req: NodeIncomingMessage | Request, routeDataOrOptions?: RouteData | RenderOptions, locals?: object) { | ||
let routeData: RouteData | undefined; | ||
|
||
if (routeDataOrOptions && ('routeData' in routeDataOrOptions || 'locals' in routeDataOrOptions)) { | ||
if ('routeData' in routeDataOrOptions) { | ||
routeData = routeDataOrOptions.routeData; | ||
} | ||
if ('locals' in routeDataOrOptions) { | ||
locals = routeDataOrOptions.locals; | ||
} | ||
} | ||
else { | ||
routeData = routeDataOrOptions as RouteData; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Do any adapters extend from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only NodeApp extends from App. Cloudflare uses App as-is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can pass this as We can also make There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe reason will be displayed to describe this comment to others. Learn more. I think my initial suggestion was incorrect. I meant If we simply pass the arguments back to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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?!