-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
fix invalidate while update #4101
Merged
Conduitry
merged 1 commit into
sveltejs:master
from
tanhauhau:tanhauhau/fix-invalidate-while-update
Dec 18, 2019
Merged
Changes from all commits
Commits
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 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
44 changes: 44 additions & 0 deletions
44
test/runtime/samples/store-invalidation-while-update-1/_config.js
This file contains 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,44 @@ | ||
export default { | ||
html: ` | ||
<input> | ||
<div></div> | ||
<div>simple</div> | ||
<button>click me</button> | ||
`, | ||
|
||
async test({ assert, component, target, window }) { | ||
const input = target.querySelector('input'); | ||
const button = target.querySelector('button'); | ||
|
||
const inputEvent = new window.InputEvent('input'); | ||
const clickEvent = new window.MouseEvent('click'); | ||
|
||
input.value = 'foo'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<input> | ||
<div>foo</div> | ||
<div>foo</div> | ||
<button>click me</button> | ||
`); | ||
|
||
await button.dispatchEvent(clickEvent); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<input> | ||
<div>foo</div> | ||
<div>clicked</div> | ||
<button>click me</button> | ||
`); | ||
|
||
input.value = 'bar'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<input> | ||
<div>bar</div> | ||
<div>bar</div> | ||
<button>click me</button> | ||
`); | ||
} | ||
}; |
20 changes: 20 additions & 0 deletions
20
test/runtime/samples/store-invalidation-while-update-1/main.svelte
This file contains 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,20 @@ | ||
<script> | ||
import {writable} from 'svelte/store'; | ||
|
||
function action(node, binding) { | ||
return { | ||
update: (value) => s.set(value), | ||
} | ||
} | ||
let s = writable("simple"); | ||
let v = ""; | ||
|
||
function click() { | ||
s.set('clicked'); | ||
} | ||
</script> | ||
|
||
<input bind:value={v} use:action={v}> | ||
<div>{v}</div> | ||
<div>{$s}</div> | ||
<button on:click={click}>click me</button> |
44 changes: 44 additions & 0 deletions
44
test/runtime/samples/store-invalidation-while-update-2/_config.js
This file contains 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,44 @@ | ||
export default { | ||
html: ` | ||
<div></div> | ||
<div>simple</div> | ||
<input> | ||
<button>click me</button> | ||
`, | ||
|
||
async test({ assert, component, target, window }) { | ||
const input = target.querySelector('input'); | ||
const button = target.querySelector('button'); | ||
|
||
const inputEvent = new window.InputEvent('input'); | ||
const clickEvent = new window.MouseEvent('click'); | ||
|
||
input.value = 'foo'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<div>foo</div> | ||
<div>foo</div> | ||
<input> | ||
<button>click me</button> | ||
`); | ||
|
||
await button.dispatchEvent(clickEvent); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<div>foo</div> | ||
<div>clicked</div> | ||
<input> | ||
<button>click me</button> | ||
`); | ||
|
||
input.value = 'bar'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<div>bar</div> | ||
<div>bar</div> | ||
<input> | ||
<button>click me</button> | ||
`); | ||
} | ||
}; |
20 changes: 20 additions & 0 deletions
20
test/runtime/samples/store-invalidation-while-update-2/main.svelte
This file contains 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,20 @@ | ||
<script> | ||
import {writable} from 'svelte/store'; | ||
|
||
function action(node, binding) { | ||
return { | ||
update: (value) => s.set(value), | ||
} | ||
} | ||
let s = writable("simple"); | ||
let v = ""; | ||
|
||
function click() { | ||
s.set('clicked'); | ||
} | ||
</script> | ||
|
||
<div>{v}</div> | ||
<div>{$s}</div> | ||
<input bind:value={v} use:action={v}> | ||
<button on:click={click}>click me</button> |
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.
This will cause update to refresh everything, whether changed or not.
Also, we need to be sure that the action callback is only triggered once.
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 thought of another oops... what if the 32nd element is invalidated?
We'd lose the bit since the special
[-1]
is not handled insidep
.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.
only have 31 bit per item in the array, if i understand correctly,
https://github.com/sveltejs/svelte/blob/master/src/compiler/compile/render_dom/Renderer.ts#L216-L217
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.
@tanhauhau,
I think I'm losing it because I thought I saw the fragment update called twice but it is only once.... so nevermind, you are absolutely correct here.
Since this change exists in the other PR, we should close this out.