Skip to content

Commit

Permalink
improvements for handling vue-loader functional components with style…
Browse files Browse the repository at this point in the history
… injections
  • Loading branch information
yyx990803 committed May 2, 2017
1 parent 8d7ad19 commit 8dc4215
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/core/vdom/create-functional-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function createFunctionalComponent (
})
if (vnode instanceof VNode) {
vnode.functionalContext = context
vnode.functionalOptions = Ctor.options
if (data.slot) {
(vnode.data || (vnode.data = {})).slot = data.slot
}
Expand Down
29 changes: 19 additions & 10 deletions src/server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,26 @@ function renderNode (node, isRoot, context) {
}
}

function registerComponentForCache (options, write) {
// exposed by vue-loader, need to call this if cache hit because
// component lifecycle hooks will not be called.
const register = options._ssrRegister
if (write.caching && isDef(register)) {
write.componentBuffer[write.componentBuffer.length - 1].add(register)
}
return register
}

function renderComponent (node, isRoot, context) {
const { write, next, userContext } = context

// check cache hit
const Ctor = node.componentOptions.Ctor
const getKey = Ctor.options.serverCacheKey
const name = Ctor.options.name

// exposed by vue-loader, need to call this if cache hit because
// component lifecycle hooks will not be called.
const registerComponent = Ctor.options._ssrRegister
if (write.caching && isDef(registerComponent)) {
write.componentBuffer[write.componentBuffer.length - 1].add(registerComponent)
}

const cache = context.cache
const registerComponent = registerComponentForCache(Ctor.options, write)

if (isDef(getKey) && isDef(cache) && isDef(name)) {
const key = name + '::' + getKey(node.componentOptions.propsData)
const { has, get } = context
Expand Down Expand Up @@ -147,7 +151,6 @@ function renderComponentInner (node, isRoot, context) {
node,
context.activeInstance
)
node.ssrContext = null
normalizeRender(child)
const childNode = child._render()
childNode.parent = node
Expand All @@ -159,14 +162,20 @@ function renderComponentInner (node, isRoot, context) {
}

function renderElement (el, isRoot, context) {
const { write, next } = context

if (isTrue(isRoot)) {
if (!el.data) el.data = {}
if (!el.data.attrs) el.data.attrs = {}
el.data.attrs[SSR_ATTR] = 'true'
}

if (el.functionalOptions) {
registerComponentForCache(el.functionalOptions, write)
}

const startTag = renderStartingTag(el, context)
const endTag = `</${el.tag}>`
const { write, next } = context
if (context.isUnaryTag(el.tag)) {
write(startTag, next)
} else if (isUndef(el.children) || el.children.length === 0) {
Expand Down

0 comments on commit 8dc4215

Please sign in to comment.