Skip to content

Commit acadd1c

Browse files
yyx990803hefeng
authored and
hefeng
committed
fix(ssr): expose context.styles when no lifecycle styles are injected
fix vuejs#6353
1 parent 0c1a8e2 commit acadd1c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,23 @@ export function createBundleRunner (entry, files, basedir, runInNewContext) {
130130
if (initialContext._styles) {
131131
userContext._styles = deepClone(initialContext._styles)
132132
}
133-
resolve(runner(userContext))
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
140+
}
141+
resolve(app)
142+
}
143+
144+
const res = runner(userContext)
145+
if (typeof res.then === 'function') {
146+
res.then(exposeStylesAndResolve)
147+
} else {
148+
exposeStylesAndResolve(res)
149+
}
134150
})
135151
}
136152
}

0 commit comments

Comments
 (0)