Skip to content

Commit

Permalink
fix(ssr): expose context.styles when no lifecycle styles are injected
Browse files Browse the repository at this point in the history
fix #6353
  • Loading branch information
yyx990803 committed Sep 13, 2017
1 parent 09106f0 commit 1f52a2a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/server/bundle-renderer/create-bundle-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,23 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
if (initialContext._styles) {
userContext._styles = deepClone(initialContext._styles)
}
resolve(runner(userContext))
// #6353 after the app is resolved, if the userContext doesn't have a
// styles property, it means the app doesn't have any lifecycle-injected
// styles, so vue-style-loader never defined the styles getter.
// just expose the same styles from the initialContext.
const exposeStylesAndResolve = app => {
if (!userContext.hasOwnProperty('styles')) {
userContext.styles = initialContext.styles

This comment has been minimized.

Copy link
@JounQin

JounQin Sep 14, 2017

Contributor

What if user wants to add some custom style into userContext._styles in this case?
For example I'm generating theme style via string template manually and injecting them into userContext._styles.

This comment has been minimized.

Copy link
@yyx990803

yyx990803 Sep 14, 2017

Author Member

You shouldn't do it... that's why userContext._styles is private. It is meant for vue-style-loader only. For your custom styles, just attach your styles in a custom property on the context and render it yourself.

}
resolve(app)
}

const res = runner(userContext)
if (typeof res.then === 'function') {
res.then(exposeStylesAndResolve)
} else {
exposeStylesAndResolve(res)
}
})
}
}

0 comments on commit 1f52a2a

Please sign in to comment.