Skip to content

Commit 843573a

Browse files
committed
chore: don't swallow rejected promise errors
1 parent e4faa78 commit 843573a

File tree

9 files changed

+52
-25
lines changed

9 files changed

+52
-25
lines changed

eslint.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ import lube from 'eslint-plugin-lube';
55
export default [
66
...svelte_config,
77
{
8+
languageOptions: {
9+
parserOptions: {
10+
project: true
11+
}
12+
},
813
plugins: {
914
lube
1015
},
1116
rules: {
17+
'@typescript-eslint/await-thenable': 'error',
18+
'@typescript-eslint/no-floating-promises': 'error',
19+
'@typescript-eslint/no-misused-promises': 'error',
20+
'@typescript-eslint/require-await': 'error',
1221
'no-console': 'error',
1322
'lube/svelte-naming-convention': ['error', { fixSameNames: true }],
1423
// eslint isn't that well-versed with JSDoc to know that `foo: /** @type{..} */ (foo)` isn't a violation of this rule, so turn it off
@@ -43,7 +52,6 @@ export default [
4352
'documentation',
4453
// contains a fork of the REPL which doesn't adhere to eslint rules
4554
'sites/svelte-5-preview/**',
46-
'playgrounds/demo/src/**',
4755
'tmp/**',
4856
// wasn't checked previously, reenable at some point
4957
'sites/svelte.dev/**'

packages/svelte/src/internal/client/dom/elements/custom-element.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,18 @@ if (typeof HTMLElement === 'function') {
193193
disconnectedCallback() {
194194
this.$$cn = false;
195195
// In a microtask, because this could be a move within the DOM
196-
Promise.resolve().then(() => {
197-
if (!this.$$cn && this.$$c) {
198-
this.$$c.$destroy();
199-
destroy_effect(this.$$me);
200-
this.$$c = undefined;
201-
}
202-
});
196+
Promise.resolve()
197+
.then(() => {
198+
if (!this.$$cn && this.$$c) {
199+
this.$$c.$destroy();
200+
destroy_effect(this.$$me);
201+
this.$$c = undefined;
202+
}
203+
})
204+
.catch((err) => {
205+
// eslint-disable-next-line no-console
206+
console.error(err);
207+
});
203208
}
204209

205210
/**

packages/svelte/src/internal/client/dom/elements/misc.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,19 @@ export function add_form_reset_listener() {
4242
(evt) => {
4343
// Needs to happen one tick later or else the dom properties of the form
4444
// elements have not updated to their reset values yet
45-
Promise.resolve().then(() => {
46-
if (!evt.defaultPrevented) {
47-
for (const e of /**@type {HTMLFormElement} */ (evt.target).elements) {
48-
// @ts-expect-error
49-
e.__on_r?.();
45+
Promise.resolve()
46+
.then(() => {
47+
if (!evt.defaultPrevented) {
48+
for (const e of /**@type {HTMLFormElement} */ (evt.target).elements) {
49+
// @ts-expect-error
50+
e.__on_r?.();
51+
}
5052
}
51-
}
52-
});
53+
})
54+
.catch((err) => {
55+
// eslint-disable-next-line no-console
56+
console.error(err);
57+
});
5358
},
5459
// In the capture phase to guarantee we get noticed of it (no possiblity of stopPropagation)
5560
{ capture: true }

packages/svelte/src/internal/client/runtime.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,12 @@ export function schedule_effect(signal) {
635635
} else if (current_scheduler_mode === FLUSH_YIELD) {
636636
if (!is_yield_task_queued) {
637637
is_yield_task_queued = true;
638-
yield_tick().then(process_deferred);
638+
yield_tick()
639+
.then(process_deferred)
640+
.catch((err) => {
641+
// eslint-disable-next-line no-console
642+
console.error(err);
643+
});
639644
}
640645
}
641646

packages/svelte/src/motion/spring.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,14 @@ export function spring(value, opts = {}) {
120120
});
121121
}
122122
return new Promise((fulfil) => {
123-
/** @type {import('../internal/client/types').Task} */ (task).promise.then(() => {
124-
if (token === current_token) fulfil();
125-
});
123+
/** @type {import('../internal/client/types').Task} */ (task).promise
124+
.then(() => {
125+
if (token === current_token) fulfil();
126+
})
127+
.catch((err) => {
128+
// eslint-disable-next-line no-console
129+
console.error(err);
130+
});
126131
});
127132
}
128133
/** @type {import('./public.js').Spring<T>} */

playgrounds/demo/.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

playgrounds/demo/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"ssr": "node ./server.js",
1010
"build": "vite build --outDir dist/client && vite build --outDir dist/server --ssr src/entry-server.ts",
1111
"prod": "npm run build && node dist",
12-
"preview": "vite preview",
13-
"format": "prettier --check --write .",
14-
"lint": "prettier --check . && eslint"
12+
"preview": "vite preview"
1513
},
1614
"devDependencies": {
1715
"@sveltejs/vite-plugin-svelte": "^3.1.0",

playgrounds/sandbox/run.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ function mkdirp(dir) {
2929
const svelte_modules = glob('**/*.svelte', { cwd: `${cwd}/input` });
3030
const js_modules = glob('**/*.js', { cwd: `${cwd}/input` });
3131

32-
for (const generate of ['client', 'server']) {
32+
/** @type {Array<'client'|'server'>} */
33+
const compile_types = ['client', 'server'];
34+
for (const generate of compile_types) {
3335
console.error(`\n--- generating ${generate} ---\n`);
3436
for (const file of svelte_modules) {
3537
const input = `${cwd}/input/${file}`;

playgrounds/sandbox/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"allowJs": true,
1414
"checkJs": true
1515
},
16-
"include": ["./input"]
16+
"include": ["./run.js", "./input"]
1717
}

0 commit comments

Comments
 (0)