A RetroSearch Logo

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

Search Query:

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

fix SSR for async functional components · vuejs/vue@882e719 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+79

-4

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+79

-4

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

@@ -67,13 +67,18 @@ export class RenderContext {

67 67

}

68 68

switch (lastState.type) {

69 69

case 'Element':

70 +

case 'Fragment':

70 71

const { children, total } = lastState

71 72

const rendered = lastState.rendered++

72 73

if (rendered < total) {

73 74

this.renderNode(children[rendered], false, this)

74 75

} else {

75 76

this.renderStates.pop()

76 -

this.write(lastState.endTag, this.next)

77 +

if (lastState.endTag) {

78 +

this.write(lastState.endTag, this.next)

79 +

} else {

80 +

this.next()

81 +

}

77 82

}

78 83

break

79 84

case 'Component':

Original file line number Diff line number Diff line change

@@ -191,7 +191,21 @@ function renderAsyncComponent (node, isRoot, context) {

191 191

tag

192 192

)

193 193

if (resolvedNode) {

194 -

renderComponent(resolvedNode, isRoot, context)

194 +

if (resolvedNode.componnetInstance) {

195 +

renderComponent(resolvedNode, isRoot, context)

196 +

} else if (!Array.isArray(resolvedNode)) {

197 +

// single return node from functional component

198 +

renderNode(resolvedNode, isRoot, context)

199 +

} else {

200 +

// multiple return nodes from functional component

201 +

context.renderStates.push({

202 +

type: 'Fragment',

203 +

children: resolvedNode,

204 +

rendered: 0,

205 +

total: resolvedNode.length

206 +

})

207 +

context.next()

208 +

}

195 209

} else {

196 210

// invalid component, but this does not throw on the client

197 211

// so render empty comment node

@@ -232,9 +246,10 @@ function renderStringNode (el, context) {

232 246

const children: Array<VNode> = el.children

233 247

context.renderStates.push({

234 248

type: 'Element',

249 +

children,

235 250

rendered: 0,

236 251

total: children.length,

237 -

endTag: el.close, children

252 +

endTag: el.close

238 253

})

239 254

write(el.open, next)

240 255

}

@@ -263,9 +278,10 @@ function renderElement (el, isRoot, context) {

263 278

const children: Array<VNode> = el.children

264 279

context.renderStates.push({

265 280

type: 'Element',

281 +

children,

266 282

rendered: 0,

267 283

total: children.length,

268 -

endTag, children

284 +

endTag

269 285

})

270 286

write(startTag, next)

271 287

}

Original file line number Diff line number Diff line change

@@ -575,6 +575,60 @@ describe('SSR: renderToString', () => {

575 575

})

576 576

})

577 577 578 +

it('renders async component (functional, single node)', done => {

579 +

renderVmWithOptions({

580 +

template: `

581 +

<div>

582 +

<test-async></test-async>

583 +

</div>

584 +

`,

585 +

components: {

586 +

testAsync (resolve) {

587 +

setTimeout(() => resolve({

588 +

functional: true,

589 +

render (h) {

590 +

return h('span', { class: ['b'] }, 'testAsync')

591 +

}

592 +

}), 1)

593 +

}

594 +

}

595 +

}, result => {

596 +

expect(result).toContain('<div data-server-rendered="true"><span class="b">testAsync</span></div>')

597 +

done()

598 +

})

599 +

})

600 + 601 +

it('renders async component (functional, multiple nodes)', done => {

602 +

renderVmWithOptions({

603 +

template: `

604 +

<div>

605 +

<test-async></test-async>

606 +

</div>

607 +

`,

608 +

components: {

609 +

testAsync (resolve) {

610 +

setTimeout(() => resolve({

611 +

functional: true,

612 +

render (h) {

613 +

return [

614 +

h('span', { class: ['a'] }, 'foo'),

615 +

h('span', { class: ['b'] }, 'bar')

616 +

]

617 +

}

618 +

}), 1)

619 +

}

620 +

}

621 +

}, result => {

622 +

expect(result).toContain(

623 +

'<div data-server-rendered="true">' +

624 +

'<span class="a">foo</span>' +

625 +

'<span class="b">bar</span>' +

626 +

'</div>'

627 +

)

628 +

done()

629 +

})

630 +

})

631 + 578 632

it('should catch async component error', done => {

579 633

Vue.config.silent = true

580 634

renderToString(new Vue({

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