mirror of https://github.com/sveltejs/svelte
- block on async work - error at compile time on await expressions. Right now it gives confusing errors later at compile time or at runtime Fixes #17194pull/17198/head
parent
9ccbd734f2
commit
b3ed454edb
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: error at compile time instead of at runtime on await expressions inside bindings/transitions/animations/attachments
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: take async blockers into account for bindings/transitions/animations/attachments
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
/** @import { Context } from '../types' */
|
||||||
|
/** @import { AST } from '#compiler'; */
|
||||||
|
import * as e from '../../../errors.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AST.AnimateDirective} node
|
||||||
|
* @param {Context} context
|
||||||
|
*/
|
||||||
|
export function AnimateDirective(node, context) {
|
||||||
|
context.next({ ...context.state, expression: node.metadata.expression });
|
||||||
|
|
||||||
|
if (node.metadata.expression.has_await) {
|
||||||
|
e.illegal_await_expression(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['client', 'hydrate'],
|
||||||
|
async test({ assert, logs }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['ready']);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
|
||||||
|
// Wait a macrotask to make sure the effect doesn't run before the microtask-Promise.resolve() resolves, masking a bug
|
||||||
|
await new Promise(r => setTimeout(r));
|
||||||
|
|
||||||
|
function run(_, arg) {
|
||||||
|
console.log(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
let value = $state('ready');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div use:run={value}></div>
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
let props = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div {...props}></div>
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['client', 'hydrate'],
|
||||||
|
async test({ assert, logs }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['ready', 'ready']);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
<script>
|
||||||
|
import Child from "./Child.svelte";
|
||||||
|
|
||||||
|
// Wait a macrotask to make sure the effect doesn't run before the microtask-Promise.resolve() resolves, masking a bug
|
||||||
|
await new Promise(r => setTimeout(r));
|
||||||
|
|
||||||
|
function createAttachment(value) {
|
||||||
|
return () => {
|
||||||
|
console.log(value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let attachment = $state('ready');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div {@attach createAttachment(attachment)}></div>
|
||||||
|
<Child {@attach createAttachment(attachment)} />
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['client', 'hydrate'],
|
||||||
|
async test({ assert, logs }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['ready']);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
// Wait a macrotask to make sure the effect doesn't run before the microtask-Promise.resolve() resolves, masking a bug
|
||||||
|
await new Promise(r => setTimeout(r));
|
||||||
|
|
||||||
|
function custom(_, value) {
|
||||||
|
console.log(value);
|
||||||
|
return { duration: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
let params = $state('ready');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div transition:custom={params}></div>
|
||||||
Loading…
Reference in new issue