-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: make fallback prop values readonly #9789
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5dc9830
WIP
Rich-Harris c263119
update tests
Rich-Harris 5fdafb1
only make readonly in runes mode
Rich-Harris ddbc5a9
remove this for now
Rich-Harris 7f97a95
changeset
Rich-Harris d884812
ugh
Rich-Harris fce95f0
add reassignment test
Rich-Harris 23064b1
tweak message
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': patch | ||
--- | ||
|
||
feat: make fallback prop values readonly |
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
15 changes: 10 additions & 5 deletions
15
packages/svelte/tests/runtime-runes/samples/class-state-derived-unowned/_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
2 changes: 2 additions & 0 deletions
2
packages/svelte/tests/runtime-runes/samples/class-state-derived-unowned/log.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,2 @@ | ||
/** @type {any[]} */ | ||
export const log = []; |
14 changes: 7 additions & 7 deletions
14
packages/svelte/tests/runtime-runes/samples/class-state-derived-unowned/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
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
2 changes: 2 additions & 0 deletions
2
packages/svelte/tests/runtime-runes/samples/class-state-init-eager-2/log.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,2 @@ | ||
/** @type {any[]} */ | ||
export const log = []; |
2 changes: 1 addition & 1 deletion
2
packages/svelte/tests/runtime-runes/samples/class-state-init-eager-2/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
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
2 changes: 2 additions & 0 deletions
2
packages/svelte/tests/runtime-runes/samples/class-state-init-eager-3/log.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,2 @@ | ||
/** @type {any[]} */ | ||
export const log = []; |
2 changes: 1 addition & 1 deletion
2
packages/svelte/tests/runtime-runes/samples/class-state-init-eager-3/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<script> | ||
const {log = []} = $props(); | ||
import { log } from './log.js'; | ||
|
||
class Counter { | ||
count = $state(); | ||
|
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
2 changes: 2 additions & 0 deletions
2
packages/svelte/tests/runtime-runes/samples/class-state-init-eager/log.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,2 @@ | ||
/** @type {any[]} */ | ||
export const log = []; |
2 changes: 1 addition & 1 deletion
2
packages/svelte/tests/runtime-runes/samples/class-state-init-eager/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<script> | ||
const {log = []} = $props(); | ||
import { log } from './log.js'; | ||
|
||
class Counter { | ||
count = $state(100); | ||
|
9 changes: 7 additions & 2 deletions
9
packages/svelte/tests/runtime-runes/samples/event-attribute-template/_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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
import { log } from './log.js'; | ||
|
||
export default test({ | ||
async test({ assert, target, component }) { | ||
before_test() { | ||
log.length = 0; | ||
}, | ||
|
||
async test({ assert, target }) { | ||
const [b1] = target.querySelectorAll('button'); | ||
|
||
flushSync(() => { | ||
b1?.click(); | ||
}); | ||
|
||
await Promise.resolve(); | ||
assert.deepEqual(component.log, ['onclick']); | ||
assert.deepEqual(log, ['onclick']); | ||
} | ||
}); |
2 changes: 2 additions & 0 deletions
2
packages/svelte/tests/runtime-runes/samples/event-attribute-template/log.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,2 @@ | ||
/** @type {any[]} */ | ||
export const log = []; |
2 changes: 1 addition & 1 deletion
2
packages/svelte/tests/runtime-runes/samples/event-attribute-template/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<script> | ||
const {log = []} = $props(); | ||
import { log } from './log.js'; | ||
|
||
function send() { | ||
log.push("onclick") | ||
|
8 changes: 8 additions & 0 deletions
8
packages/svelte/tests/runtime-runes/samples/proxy-prop-default-readonly/Counter.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,8 @@ | ||
<script> | ||
/** @type {{ object?: { count: number }}} */ | ||
let { object = { count: 0 } } = $props(); | ||
</script> | ||
|
||
<button onclick={() => object.count += 1}> | ||
clicks: {object.count} | ||
</button> |
18 changes: 18 additions & 0 deletions
18
packages/svelte/tests/runtime-runes/samples/proxy-prop-default-readonly/_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,18 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: `<button>clicks: 0</button>`, | ||
|
||
compileOptions: { | ||
dev: true | ||
}, | ||
|
||
async test({ assert, target }) { | ||
const btn = target.querySelector('button'); | ||
await btn?.click(); | ||
|
||
assert.htmlEqual(target.innerHTML, `<button>clicks: 0</button>`); | ||
}, | ||
|
||
runtime_error: 'Props are read-only, unless used with `bind:`' | ||
Rich-Harris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); |
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/runtime-runes/samples/proxy-prop-default-readonly/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,5 @@ | ||
<script> | ||
import Counter from './Counter.svelte'; | ||
</script> | ||
|
||
<Counter /> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm starting to think it might make more sense to have two versions of this – one for runes and one for legacy. I'm really unhappy that we have
sync_effect
as it's an anti-pattern, so if we can somehow get to a point where we kill that in runes, it enables us to make forking of effects work. With sync effects that happen during the notification phase, that's pretty much impossible as it means effects fire and potentially invalidate another effect tree, making forking impossible.