-
-
Couldn't load subscription status.
- Fork 2.1k
chore: cleanup promise handling #12284
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
Changes from all commits
c00b1f3
0d23637
88eeab6
6f5b2d8
c4c2175
5512a5a
13ee5f8
8874d96
336b639
743c640
24fc701
f156eaa
e244c28
e075503
f9e02f4
dd553bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,7 +233,7 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) { | |
|
|
||
| const body = Buffer.from(await response.arrayBuffer()); | ||
|
|
||
| save('pages', response, body, decoded, encoded, referrer, 'linked'); | ||
| await save('pages', response, body, decoded, encoded, referrer, 'linked'); | ||
|
|
||
| for (const [dependency_path, result] of dependencies) { | ||
| // this seems circuitous, but using new URL allows us to not care | ||
|
|
@@ -257,7 +257,7 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) { | |
|
|
||
| const body = result.body ?? new Uint8Array(await result.response.arrayBuffer()); | ||
|
|
||
| save( | ||
| await save( | ||
| 'dependencies', | ||
| result.response, | ||
| body, | ||
|
|
@@ -305,7 +305,7 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) { | |
| /** @type {Set<string>} */ (expected_hashlinks.get(key)).add(decoded); | ||
| } | ||
|
|
||
| enqueue(decoded, decode_uri(pathname), pathname); | ||
| await enqueue(decoded, decode_uri(pathname), pathname); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -319,7 +319,7 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) { | |
| * @param {string | null} referrer | ||
| * @param {'linked' | 'fetched'} referenceType | ||
| */ | ||
| function save(category, response, body, decoded, encoded, referrer, referenceType) { | ||
| async function save(category, response, body, decoded, encoded, referrer, referenceType) { | ||
| const response_type = Math.floor(response.status / 100); | ||
| const headers = Object.fromEntries(response.headers); | ||
|
|
||
|
|
@@ -341,7 +341,7 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) { | |
| if (location) { | ||
| const resolved = resolve(encoded, location); | ||
| if (is_root_relative(resolved)) { | ||
| enqueue(decoded, decode_uri(resolved), resolved); | ||
| await enqueue(decoded, decode_uri(resolved), resolved); | ||
|
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. why are we awaiting these all? I imagine this adding up when prerendering a lot of files, hurting perf in the end, and I can't really imagine there being errors that are otherwise uncaught. 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's such a quick action I didn't really imagine it adding up. I've updated it to enqueue them in parallel instead though to be safe 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. See, stuff like this is exactly why these rules are so dangerous — I'm pretty sure this creates deadlock, and I'm pretty sure that's why the tests started failing with the commit that added this. You have to treat ESLint like an idiot child. You can give it very simple tasks from time to time, but don't trust it with anything important. Let's revert all this |
||
| } | ||
|
|
||
| if (!headers['x-sveltekit-normalize']) { | ||
|
|
@@ -449,6 +449,7 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) { | |
| read: (file) => createReadableStream(`${config.outDir}/output/server/${file}`) | ||
| }); | ||
|
|
||
| const entries_to_enqueue = []; | ||
| for (const entry of config.prerender.entries) { | ||
| if (entry === '*') { | ||
| for (const [id, prerender] of prerender_map) { | ||
|
|
@@ -459,19 +460,20 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) { | |
|
|
||
| if (processed_id.includes('[')) continue; | ||
| const path = `/${get_route_segments(processed_id).join('/')}`; | ||
| enqueue(null, config.paths.base + path); | ||
| entries_to_enqueue.push({ path: config.paths.base + path }); | ||
| } | ||
| } | ||
| } else { | ||
| enqueue(null, config.paths.base + entry); | ||
| entries_to_enqueue.push({ path: config.paths.base + entry }); | ||
| } | ||
| } | ||
|
|
||
| for (const { id, entries } of route_level_entries) { | ||
| for (const entry of entries) { | ||
| enqueue(null, config.paths.base + entry, undefined, id); | ||
| entries_to_enqueue.push({ path: config.paths.base + entry, id }); | ||
| } | ||
| } | ||
| await Promise.all(entries_to_enqueue.map(({ path, id }) => enqueue(null, path, undefined, id))); | ||
|
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. why is this better than what existed before this PR? 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's clearer to me as it's explicit that we intend to enqueue them in parallel. it also handles rejected promise errors which would not be handled before. while it's a pretty simple method that's unlikely to fail, but everytime I come across something like that in a code review I have to review it and assess the risk that it might fail and it's easier for me to not have to do that 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. Rejected promise errors are handled already. That's what the |
||
|
|
||
| await q.done(); | ||
|
|
||
|
|
||
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 took a look at the errors that arise if this rule is enabled, and not a single one is valid. It's just ESLint whining pointlessly
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.
a lot more errors pop up with
no-floating-promisesand i haven't looked at them all yet, but of the ones i have looked at it's the same story. definitely not something we wantThere 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 don't understand why the issues
no-floating-promisesis identifying shouldn't be addressed. I just pushed a commit addressing a lot of them: 743c640. We can drop it if they're really not issues. This isn't my strong point, so it's quite possible I'm missing something. I figured I'd push it though so that I can at least learn what that is as it's easier to discuss that way.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.
They're really not issues, but the rule tricked you into breaking code that works perfectly well