Browse Source

fix(ssr): fix style injection regression

fix #6603, (regression caused by attempt to fix #6353)
dev
Evan You 7 years ago
parent
commit
a2f73f2c2e
  1. 30
      src/server/bundle-renderer/create-bundle-runner.js

30
src/server/bundle-renderer/create-bundle-runner.js

@ -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()
@ -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))
})
}
}

Loading…
Cancel
Save