Skip to content

Commit

Permalink
add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Oct 17, 2024
1 parent 99c0c48 commit 8fbbd55
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions documentation/docs/98-reference/.generated/legacy-warnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### legacy_reactive_block_mutation

```
Detected a migrated `$:` reactive block that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`.
```
3 changes: 3 additions & 0 deletions packages/svelte/messages/legacy-warnings/warnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## legacy_reactive_block_mutation

> Detected a migrated `$:` reactive block that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`.
1 change: 1 addition & 0 deletions packages/svelte/scripts/process-messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,4 @@ transform('client-errors', 'src/internal/client/errors.js');
transform('server-errors', 'src/internal/server/errors.js');
transform('shared-errors', 'src/internal/shared/errors.js');
transform('shared-warnings', 'src/internal/shared/warnings.js');
transform('legacy-warnings', 'src/legacy/warnings.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DEV } from 'esm-env';

var bold = 'font-weight: bold';
var normal = 'font-weight: normal';

/**
* MESSAGE
* @param {string} PARAMETER
*/
export function CODE(PARAMETER) {
if (DEV) {
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
} else {
// TODO print a link to the documentation
console.warn('CODE');
}
}
2 changes: 2 additions & 0 deletions packages/svelte/src/legacy/legacy-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../internal/client/runtime.js';
import { lifecycle_outside_component } from '../internal/shared/errors.js';
import { define_property, is_array } from '../internal/shared/utils.js';
import * as w from './warnings.js';

/**
* Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.
Expand Down Expand Up @@ -181,6 +182,7 @@ export function run(fn) {
var effect = /** @type {import('#client').Effect} */ (active_effect);
// If the effect is immediately made dirty again, mark it as maybe dirty to emulate legacy behaviour
if ((effect.f & DIRTY) !== 0) {
w.legacy_reactive_block_mutation();
set_signal_status(effect, MAYBE_DIRTY);
}
});
Expand Down
18 changes: 18 additions & 0 deletions packages/svelte/src/legacy/warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This file is generated by scripts/process-messages/index.js. Do not edit! */

import { DEV } from 'esm-env';

var bold = 'font-weight: bold';
var normal = 'font-weight: normal';

/**
* Detected a migrated `$:` reactive block that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`.
*/
export function legacy_reactive_block_mutation() {
if (DEV) {
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);

Check failure on line 13 in packages/svelte/src/legacy/warnings.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
} else {
// TODO print a link to the documentation
console.warn("legacy_reactive_block_mutation");

Check failure on line 16 in packages/svelte/src/legacy/warnings.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
}
}

0 comments on commit 8fbbd55

Please sign in to comment.