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

chore: cleanup promise handling #12284

Closed
wants to merge 16 commits into from
Closed

chore: cleanup promise handling #12284

wants to merge 16 commits into from

Conversation

benmccann
Copy link
Member

@benmccann benmccann commented May 31, 2024

Copy link

changeset-bot bot commented May 31, 2024

⚠️ No Changeset found

Latest commit: dd553bc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Some of these can't be done because they affect public API. What exactly is the purpose of the rule? To find unnecessary async functions?

packages/create-svelte/index.js Outdated Show resolved Hide resolved
packages/kit/src/exports/node/index.js Outdated Show resolved Hide resolved
@@ -19,7 +19,7 @@ if (DEV && BROWSER) {
let can_inspect_stack_trace = false;

// detect whether async stack traces work
const check_stack_trace = async () => {
const check_stack_trace = () => {
Copy link
Member

Choose a reason for hiding this comment

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

this is there for a reason! without it, we're not actually checking anything

Suggested change
const check_stack_trace = () => {
const check_stack_trace = async () => {

Copy link
Member Author

Choose a reason for hiding this comment

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

perhaps we could avoid the ignore by writing it as this?

	const check_stack_trace = () => {
		const stack = /** @type {string} */ (new Error().stack);
		can_inspect_stack_trace = stack.includes('check_stack_trace');
	};

	// detect whether async stack traces work
	Promise.resolve(check_stack_trace());

Copy link
Member

Choose a reason for hiding this comment

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

That completely misses the point, which is to find out whether stack traces cross async boundaries in the current browser.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've honestly got not idea what that means. Is this some kind of browser compatibility thing where that happens only in some browsers, but not others?

Copy link
Member

Choose a reason for hiding this comment

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

That's the purpose of it, yes. IIRC stack traces cross async boundaries in Firefox but not Chrome, for example.

rules: {
'@typescript-eslint/await-thenable': 'error',
// '@typescript-eslint/no-floating-promises': 'error',
// '@typescript-eslint/no-misused-promises': 'error',
Copy link
Member

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

Suggested change
// '@typescript-eslint/no-misused-promises': 'error',

Copy link
Member

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-promises and 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 want

Copy link
Member Author

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-promises is 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.

Copy link
Member

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

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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

packages/kit/src/runtime/client/client.js Outdated Show resolved Hide resolved
@@ -7,7 +7,7 @@ import { test as base, devices } from '@playwright/test';
export const test = base.extend({
app: async ({ page }, use) => {
// these are assumed to have been put in the global scope by the layout
use({
await use({
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't need to be awaited. none of them do

}
}
await Promise.all(entries_to_enqueue.map(({ path, id }) => enqueue(null, path, undefined, id)));
Copy link
Member

Choose a reason for hiding this comment

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

why is this better than what existed before this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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() two lines later is for. This is duplicative and less efficient, it adds nothing!

@Rich-Harris
Copy link
Member

Opened #12297 which adds the await-thenable and require-await rules but without the breaky stuff

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