Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nekuz0r opened this issue Aug 11, 2017 · 3 comments
Closed

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

nekuz0r opened this issue Aug 11, 2017 · 3 comments

Comments

@nekuz0r
Copy link

nekuz0r commented Aug 11, 2017

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')
)
JounQin added a commit to un-es/react-style-loader that referenced this issue Sep 6, 2017
It causes SSR issue like vuejs/vue#6353
@JounQin
Copy link
Contributor

JounQin commented Sep 6, 2017

@yyx990803 It's a typo which makes styles not enumerable, it should be fixed after the PR merged.

@yyx990803
Copy link
Member

@JounQin are you sure? Even if it's not enumerable it should still be present. (I haven't got time to properly investigate this issue yet)

yyx990803 pushed a commit to vuejs/vue-style-loader that referenced this issue Sep 6, 2017
It causes SSR issue like vuejs/vue#6353
@JounQin
Copy link
Contributor

JounQin commented Sep 6, 2017

Ah, sorry I read it wrong, and as I know it should not be an issue here, I'll try to figure it later.

I used to extract all styles of first chunk into .css, and also if there is another async chunk it will generate styles property correctly, so I haven't encountered this problem.

However,

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

sounds not good to me, because context in customContext getter will always be initialContext.

@JounQin JounQin mentioned this issue Sep 6, 2017
13 tasks
yyx990803 added a commit that referenced this issue Sep 14, 2017
fix #6603, (regression caused by attempt to fix #6353)
ztlevi pushed a commit to ztlevi/vue that referenced this issue Feb 14, 2018
fix vuejs#6603, (regression caused by attempt to fix vuejs#6353)
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
fix vuejs#6603, (regression caused by attempt to fix vuejs#6353)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants