Skip to content

[SSR] context.styles is undefined when runInNewContext !== true #6353

Closed
@nekuz0r

Description

Version

2.4.2

Reproduction link

https://github.com/nekuz0r/vuejs-ssr-styles-issue

Steps to reproduce

npm run build
npm run start

What is expected?

context.styles to be defined

What is actually happening?

context.styles is undefined when runInNewContext is equal false or 'once'


context.styles getter is not set on the new context created when
runInNewContext is equal to false or once.

vue-style-loader is defining a getter for context.styles property
(https://github.com/vuejs/vue-style-loader/blob/master/lib/addStylesServer.js#L9)

When runInNewContext is false or once, VueJS is copying the _styles
property in userContext from initialContext but the styles getter is not.
(

userContext._styles = deepClone(initialContext._styles)
)

Adding the following line after that one fixes the issue

Object.defineProperty(userContext, 'styles',
  Object.getOwnPropertyDescriptor(initialContext, 'styles')
)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions