Skip to content

Commit a2f73f2

Browse files
committed
fix(ssr): fix style injection regression
fix #6603, (regression caused by attempt to fix #6353)
1 parent 0c9534f commit a2f73f2

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

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

+14-16
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
106106
// slightly differently.
107107
let runner // lazy creation so that errors can be caught by user
108108
let initialContext
109-
return (userContext = {}) => new Promise((resolve, reject) => {
109+
return (userContext = {}) => new Promise(resolve => {
110110
if (!runner) {
111111
const sandbox = runInNewContext === 'once'
112112
? createSandbox()
@@ -126,27 +126,25 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
126126
}
127127
}
128128
userContext._registeredComponents = new Set()
129+
129130
// vue-style-loader styles imported outside of component lifecycle hooks
130131
if (initialContext._styles) {
131132
userContext._styles = deepClone(initialContext._styles)
132-
}
133-
// #6353 after the app is resolved, if the userContext doesn't have a
134-
// styles property, it means the app doesn't have any lifecycle-injected
135-
// styles, so vue-style-loader never defined the styles getter.
136-
// just expose the same styles from the initialContext.
137-
const exposeStylesAndResolve = app => {
138-
if (!userContext.hasOwnProperty('styles')) {
139-
userContext.styles = initialContext.styles
133+
// #6353 ensure "styles" is exposed even if no styles are injected
134+
// in component lifecycles.
135+
// the renderStyles fn is exposed by vue-style-loader >= 3.0.3
136+
const renderStyles = initialContext._renderStyles
137+
if (renderStyles) {
138+
Object.defineProperty(userContext, 'styles', {
139+
enumerable: true,
140+
get () {
141+
return renderStyles(userContext._styles)
142+
}
143+
})
140144
}
141-
resolve(app)
142145
}
143146

144-
const res = runner(userContext)
145-
if (typeof res.then === 'function') {
146-
res.then(exposeStylesAndResolve).catch(reject)
147-
} else {
148-
exposeStylesAndResolve(res)
149-
}
147+
resolve(runner(userContext))
150148
})
151149
}
152150
}

0 commit comments

Comments
 (0)