Skip to content

Commit 8fbbd55

Browse files
committed
add warning
1 parent 99c0c48 commit 8fbbd55

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### legacy_reactive_block_mutation
2+
3+
```
4+
Detected a migrated `$:` reactive block that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`.
5+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## legacy_reactive_block_mutation
2+
3+
> Detected a migrated `$:` reactive block that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`.

packages/svelte/scripts/process-messages/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,4 @@ transform('client-errors', 'src/internal/client/errors.js');
404404
transform('server-errors', 'src/internal/server/errors.js');
405405
transform('shared-errors', 'src/internal/shared/errors.js');
406406
transform('shared-warnings', 'src/internal/shared/warnings.js');
407+
transform('legacy-warnings', 'src/legacy/warnings.js');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { DEV } from 'esm-env';
2+
3+
var bold = 'font-weight: bold';
4+
var normal = 'font-weight: normal';
5+
6+
/**
7+
* MESSAGE
8+
* @param {string} PARAMETER
9+
*/
10+
export function CODE(PARAMETER) {
11+
if (DEV) {
12+
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
13+
} else {
14+
// TODO print a link to the documentation
15+
console.warn('CODE');
16+
}
17+
}

packages/svelte/src/legacy/legacy-client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '../internal/client/runtime.js';
1313
import { lifecycle_outside_component } from '../internal/shared/errors.js';
1414
import { define_property, is_array } from '../internal/shared/utils.js';
15+
import * as w from './warnings.js';
1516

1617
/**
1718
* Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.
@@ -181,6 +182,7 @@ export function run(fn) {
181182
var effect = /** @type {import('#client').Effect} */ (active_effect);
182183
// If the effect is immediately made dirty again, mark it as maybe dirty to emulate legacy behaviour
183184
if ((effect.f & DIRTY) !== 0) {
185+
w.legacy_reactive_block_mutation();
184186
set_signal_status(effect, MAYBE_DIRTY);
185187
}
186188
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* This file is generated by scripts/process-messages/index.js. Do not edit! */
2+
3+
import { DEV } from 'esm-env';
4+
5+
var bold = 'font-weight: bold';
6+
var normal = 'font-weight: normal';
7+
8+
/**
9+
* Detected a migrated `$:` reactive block that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`.
10+
*/
11+
export function legacy_reactive_block_mutation() {
12+
if (DEV) {
13+
console.warn(`%c[svelte] legacy_reactive_block_mutation\n%cDetected a migrated \`$:\` reactive block that both accesses and updates the same reactive value. This may cause recursive updates when converted to an \`$effect\`.`, bold, normal);
14+
} else {
15+
// TODO print a link to the documentation
16+
console.warn("legacy_reactive_block_mutation");
17+
}
18+
}

0 commit comments

Comments
 (0)