diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fa087e03a..e19af3e53f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix `{#each}` context not shadowing outer scope when using `bind:` ([#1565](https://github.com/sveltejs/svelte/issues/1565)) * Fix edge cases in matching selectors against elements ([#1710](https://github.com/sveltejs/svelte/issues/1710)) +* Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index d193508a89..00157cc256 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -98,6 +98,8 @@ export default function ssr( : b` let ${left} = ${right}`; } + } else { // TODO do not add label if it's not referenced + statement = b`$: { ${statement} }`; } return statement; diff --git a/test/runtime/samples/reactive-block-break/_config.js b/test/runtime/samples/reactive-block-break/_config.js new file mode 100644 index 0000000000..f2d3e6a8f5 --- /dev/null +++ b/test/runtime/samples/reactive-block-break/_config.js @@ -0,0 +1,3 @@ +export default { + html: `

1 2

` +}; \ No newline at end of file diff --git a/test/runtime/samples/reactive-block-break/main.svelte b/test/runtime/samples/reactive-block-break/main.svelte new file mode 100644 index 0000000000..5b0aa005c0 --- /dev/null +++ b/test/runtime/samples/reactive-block-break/main.svelte @@ -0,0 +1,14 @@ + + +

{foo} {bar}

\ No newline at end of file