Skip to content

Conversation

@PuruVJ
Copy link
Collaborator

@PuruVJ PuruVJ commented Jul 11, 2023

  • Updates deps of hn.svelte.dev
  • Switches to using edge runtime for faster performance and less impact on environment

@vercel
Copy link

vercel bot commented Jul 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hn ✅ Ready (Inspect) Visit Preview Jul 18, 2023 4:27am
repl ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2023 4:27am

export async function load({ params, fetch }) {
const res = await fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`);
return res.json();
return fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`).then((r) => r.json());
Copy link
Member

Choose a reason for hiding this comment

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

making it one line makes sense, but why not use await still?

Suggested change
return fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`).then((r) => r.json());
return (await fetch(`https://api.hnpwa.com/v0/user/${params.name}.json`)).json();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dunno, await has felt weird when surrounded by brackets. .then feels cleaner for this case somehow

Copy link
Member

Choose a reason for hiding this comment

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

What happens if invalid JSON is returned from the API? I think the two ways of writing it would behave differently, but I'm not exactly sure what the behavior of the .then() version is

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the same. If it errors, then .json() errors out, giving the same error as await version

@benmccann benmccann merged commit 00110e5 into master Jul 18, 2023
@benmccann benmccann deleted the renovate-hn branch July 18, 2023 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants