Skip to content

Commit

Permalink
fix(nitro): workaround for vue2 global style injection
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 16, 2021
1 parent 5cb102b commit f1b74d0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/runtime/app/vue2.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
// @ts-ignore
import { createRenderer } from '~vueServerRenderer'

const _renderer = createRenderer({})

// @ts-ignore
const __VUE_SSR_CONTEXT__ = global.__VUE_SSR_CONTEXT__ = {}

export function renderToString (component, context) {
return new Promise((resolve, reject) => {
_renderer.renderToString(component, context, (err, result) => {
const styles = [__VUE_SSR_CONTEXT__, context].map(c => c?._styles?.default).filter(Boolean)
if (!context._styles) { context._styles = {} }
context._styles.default = {
ids: [...styles.map(s => s.ids)],
css: styles.map(s => s.css).join(''),
media: styles.map(s => s.media).join('')
}
if (err) {
return reject(err)
}
Expand Down

0 comments on commit f1b74d0

Please sign in to comment.