Skip to content
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(runtime-core): handle patch stable fragment edge case #12411

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,8 @@ function baseCreateRenderer(
dynamicChildren &&
// #2715 the previous fragment could've been a BAILed one as a result
// of renderSlot() with no valid children
n1.dynamicChildren
n1.dynamicChildren &&
n1.dynamicChildren.length === dynamicChildren.length
) {
// a stable fragment (template root or <template v-for>) doesn't need to
// patch children order, but it may contain dynamicChildren.
Expand Down
30 changes: 30 additions & 0 deletions packages/vue/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,34 @@ describe('compiler + runtime integration', () => {
app.mount(root)
expect(root.innerHTML).toBe('<div>60000000100000111</div>')
})

test('should correctly update when reactive state and normal array are modified', async () => {
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
const count = ref(0)
const foo: any[] = []
function updateFoo() {
for (let n = 0; n < 3; n++) {
foo[n] = n + 1 + '_foo'
}
}
const app = createApp({
setup() {
return {
count,
foo,
}
},
template: `
<div>{{count}}</div>
<div v-for='item in foo'>{{ item }}</div>`,
})
const root = document.createElement('div')
app.mount(root)
expect(root.innerHTML).toBe('<div>0</div>')
updateFoo()
count.value++
await nextTick()
expect(root.innerHTML).toBe(
'<div>1</div><div>1_foo</div><div>2_foo</div><div>3_foo</div>',
)
})
})