Skip to content

Commit

Permalink
feat(ssr): inheritAttrs support in SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 12, 2017
1 parent 1bf98b0 commit 6bf9772
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/platforms/web/server/modules/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ export default function renderAttrs (node: VNodeWithData): string {
let attrs = node.data.attrs
let res = ''

let parent = node.parent
while (isDef(parent)) {
if (isDef(parent.data) && isDef(parent.data.attrs)) {
attrs = Object.assign({}, attrs, parent.data.attrs)
const opts = node.parent && node.parent.componentOptions
if (isUndef(opts) || opts.Ctor.options.inheritAttrs !== false) {
let parent = node.parent
while (isDef(parent)) {
if (isDef(parent.data) && isDef(parent.data.attrs)) {
attrs = Object.assign({}, attrs, parent.data.attrs)
}
parent = parent.parent
}
parent = parent.parent
}

if (isUndef(attrs)) {
Expand Down
15 changes: 15 additions & 0 deletions test/ssr/ssr-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,21 @@ describe('SSR: renderToString', () => {
done()
})
})

it('with inheritAttrs: false + $attrs', done => {
renderVmWithOptions({
template: `<foo id="a"/>`,
components: {
foo: {
inheritAttrs: false,
template: `<div><div v-bind="$attrs"></div></div>`
}
}
}, res => {
expect(res).toBe(`<div data-server-rendered="true"><div id="a"></div></div>`)
done()
})
})
})

function renderVmWithOptions (options, cb) {
Expand Down

0 comments on commit 6bf9772

Please sign in to comment.