A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue/commit/b080a14138262f0f274d0888555a11bd7387d576 below:

fix hydration mismatch with adjacent text node from slots · vuejs/vue@b080a14 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+32

-6

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+32

-6

lines changed Original file line number Diff line number Diff line change

@@ -42,28 +42,35 @@ function isTextNode (node): boolean {

42 42 43 43

function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNode> {

44 44

const res = []

45 -

let i, c, last

45 +

let i, c, lastIndex, last

46 46

for (i = 0; i < children.length; i++) {

47 47

c = children[i]

48 48

if (isUndef(c) || typeof c === 'boolean') continue

49 -

last = res[res.length - 1]

49 +

lastIndex = res.length - 1

50 +

last = res[lastIndex]

50 51

// nested

51 -

if (Array.isArray(c)) {

52 -

res.push.apply(res, normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`))

52 +

if (Array.isArray(c) && c.length > 0) {

53 +

c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`)

54 +

// merge adjacent text nodes

55 +

if (isTextNode(c[0]) && isTextNode(last)) {

56 +

res[lastIndex] = createTextVNode(last.text + (c[0]: any).text)

57 +

c.shift()

58 +

}

59 +

res.push.apply(res, c)

53 60

} else if (isPrimitive(c)) {

54 61

if (isTextNode(last)) {

55 62

// merge adjacent text nodes

56 63

// this is necessary for SSR hydration because text nodes are

57 64

// essentially merged when rendered to HTML strings

58 -

(last: any).text += String(c)

65 +

res[lastIndex] = createTextVNode(last.text + c)

59 66

} else if (c !== '') {

60 67

// convert primitive to vnode

61 68

res.push(createTextVNode(c))

62 69

}

63 70

} else {

64 71

if (isTextNode(c) && isTextNode(last)) {

65 72

// merge adjacent text nodes

66 -

res[res.length - 1] = createTextVNode(last.text + c.text)

73 +

res[lastIndex] = createTextVNode(last.text + c.text)

67 74

} else {

68 75

// default key for nested array children (likely generated by v-for)

69 76

if (isTrue(children._isVList) &&

Original file line number Diff line number Diff line change

@@ -323,4 +323,23 @@ describe('vdom patch: hydration', () => {

323 323 324 324

expect('not matching server-rendered content').toHaveBeenWarned()

325 325

})

326 + 327 +

it('should hydrate with adjacent text nodes from array children (e.g. slots)', () => {

328 +

const dom = createMockSSRDOM('<div>foo</div> hello')

329 + 330 +

new Vue({

331 +

template: `<test>hello</test>`,

332 +

components: {

333 +

test: {

334 +

template: `

335 +

<div>

336 +

<div>foo</div>

337 +

<slot/>

338 +

</div>

339 +

`

340 +

}

341 +

}

342 +

}).$mount(dom)

343 +

expect('not matching server-rendered content').not.toHaveBeenWarned()

344 +

})

326 345

})

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4