Skip to content

When to use async in routes and when not? #1712

Closed Answered by marvinhagemeister
nilslindemann asked this question in Q&A
Discussion options

You must be logged in to vote

Synchronous components are bog standard Preact components. Because of that they do not receive Request as an argument to the function, but rather a standard props object. This is typed as PageProps like in your first snippet. That in turn receives the request url via props.url, which makes your example accidentally work, even though you mistyped props as being Request. Both have a url property. What's really happening is this here:

// Sync route components receives props, NOT a Request instance
export default function Page(props: PageProps) {
  // The `props.url` property is already a `URL` instance,
  // because it's not a `Request` object, rather an object created by us.
  // So this li…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nilslindemann
Comment options

Answer selected by nilslindemann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants