-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: turn reactive_declaration_non_reactive_property into a runtime warning
#14192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c27510f
turn `reactive_declaration_non_reactive_property` into a runtime warning
Rich-Harris 15dc2b9
ignore warning
Rich-Harris 1a71f61
Update packages/svelte/src/internal/client/reactivity/effects.js
Rich-Harris 45a67ee
Update packages/svelte/src/internal/client/runtime.js
Rich-Harris db46ad7
fix
Rich-Harris f3804ca
test
Rich-Harris 0eb1e3d
changeset
Rich-Harris af1060f
merge main
Rich-Harris 669ecf4
Update .changeset/witty-turtles-bake.md
Rich-Harris f2036a8
add some details
Rich-Harris 632f7d2
Merge branch 'gh-14111-alternative' of github.com:sveltejs/svelte int…
Rich-Harris 2627c3c
check
Rich-Harris 2207b7d
regenerate
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'svelte': minor | ||
| --- | ||
|
|
||
| feat: turn reactive_declaration_non_reactive_property into a runtime warning | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { DEV } from 'esm-env'; | ||
| import { FILENAME } from '../../../constants.js'; | ||
| import { dev_current_component_function } from '../runtime.js'; | ||
|
|
||
| /** | ||
| * | ||
| * @param {number} [line] | ||
| * @param {number} [column] | ||
| */ | ||
| export function get_location(line, column) { | ||
| if (!DEV || line === undefined) return undefined; | ||
|
|
||
| var filename = dev_current_component_function?.[FILENAME]; | ||
| var location = filename && `${filename}:${line}:${column}`; | ||
|
|
||
| return sanitize_location(location); | ||
| } | ||
|
|
||
| /** | ||
| * Prevent devtools trying to make `location` a clickable link by inserting a zero-width space | ||
| * @param {string | undefined} location | ||
| */ | ||
| export function sanitize_location(location) { | ||
| return location?.replace(/\//g, '/\u200b'); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../tests/runtime-legacy/samples/reactive-statement-non-reactive-import-statement/_config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { flushSync } from 'svelte'; | ||
| import { test } from '../../test'; | ||
|
|
||
| export default test({ | ||
| compileOptions: { | ||
| dev: true | ||
| }, | ||
|
|
||
| html: '<p>42</p><p>42</p><button>update</button><button>reset</button>', | ||
|
|
||
| test({ assert, target }) { | ||
| const [update, reset] = target.querySelectorAll('button'); | ||
| flushSync(() => update.click()); | ||
|
|
||
| assert.htmlEqual( | ||
| target.innerHTML, | ||
| '<p>42</p><p>42</p><button>update</button><button>reset</button>' | ||
| ); | ||
|
|
||
| flushSync(() => reset.click()); | ||
| }, | ||
|
|
||
| warnings: [ | ||
| 'A `$:` statement (main.svelte:4:1) read reactive state that was not visible to the compiler. Updates to this state will not cause the statement to re-run. The behaviour of this code will change if you migrate it to runes mode' | ||
| ] | ||
| }); |
11 changes: 11 additions & 0 deletions
11
...ts/runtime-legacy/samples/reactive-statement-non-reactive-import-statement/data.svelte.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export const obj = $state({ | ||
| prop: 42 | ||
| }); | ||
|
|
||
| export function update() { | ||
| obj.prop += 1; | ||
| } | ||
|
|
||
| export function reset() { | ||
| obj.prop = 42; | ||
| } |
13 changes: 13 additions & 0 deletions
13
...tests/runtime-legacy/samples/reactive-statement-non-reactive-import-statement/main.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <script> | ||
| import { obj, update, reset } from './data.svelte.js'; | ||
|
|
||
| $: a = obj.prop; | ||
|
|
||
| // svelte-ignore reactive_declaration_non_reactive_property | ||
| $: b = obj.prop; | ||
| </script> | ||
|
|
||
| <p>{a}</p> | ||
| <p>{b}</p> | ||
| <button on:click={update}>update</button> | ||
| <button on:click={reset}>reset</button> |
3 changes: 0 additions & 3 deletions
3
...velte/tests/validator/samples/reactive-statement-non-reactive-import-statement/_config.js
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...lte/tests/validator/samples/reactive-statement-non-reactive-import-statement/input.svelte
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.