Skip to content

Commit

Permalink
fix(ssr): fix style injection regression
Browse files Browse the repository at this point in the history
fix #6603, (regression caused by attempt to fix #6353)
  • Loading branch information
yyx990803 committed Sep 14, 2017
1 parent 0c9534f commit a2f73f2
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/server/bundle-renderer/create-bundle-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
// slightly differently.
let runner // lazy creation so that errors can be caught by user
let initialContext
return (userContext = {}) => new Promise((resolve, reject) => {
return (userContext = {}) => new Promise(resolve => {
if (!runner) {
const sandbox = runInNewContext === 'once'
? createSandbox()
Expand All @@ -126,27 +126,25 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
}
}
userContext._registeredComponents = new Set()

// vue-style-loader styles imported outside of component lifecycle hooks
if (initialContext._styles) {
userContext._styles = deepClone(initialContext._styles)
}
// #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
// #6353 ensure "styles" is exposed even if no styles are injected
// in component lifecycles.
// the renderStyles fn is exposed by vue-style-loader >= 3.0.3
const renderStyles = initialContext._renderStyles
if (renderStyles) {
Object.defineProperty(userContext, 'styles', {
enumerable: true,
get () {
return renderStyles(userContext._styles)
}
})
}
resolve(app)
}

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

0 comments on commit a2f73f2

Please sign in to comment.