From a2f73f2c2e28771e6597334bd86f82851ce0955e Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 Sep 2017 10:54:59 -0400 Subject: [PATCH] fix(ssr): fix style injection regression fix #6603, (regression caused by attempt to fix #6353) --- .../bundle-renderer/create-bundle-runner.js | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/server/bundle-renderer/create-bundle-runner.js b/src/server/bundle-renderer/create-bundle-runner.js index dd1e5373937..a0e1d283aa1 100644 --- a/src/server/bundle-renderer/create-bundle-runner.js +++ b/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)) }) } }