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

scoped styles are not immediately rendered #348

Closed
43081j opened this issue Jun 4, 2020 · 1 comment
Closed

scoped styles are not immediately rendered #348

43081j opened this issue Jun 4, 2020 · 1 comment

Comments

@43081j
Copy link
Contributor

43081j commented Jun 4, 2020

Hello 👋

I was poking around the repo and noticed an oddity with scoped styles.

Let's say you have this in a component somewhere (I used vite-app):

<template>
  <h1>Blah</h1>
</template>

If you load it up using vite, all is fine. If you then change it to this:

<style scoped> h1 { color: blue; } </style>

<template>
  <h1>Blah</h1>
</template>

It does not render the new colour.

Having stepped through this, i'm not sure if its vue's fault or if its vite's fault...

  • vite emits a style-update message correctly
  • the client sees this correctly and imports the style
  • the imported style correctly adds its self to the <head> with the correct scope ID
  • the DOM is not updated to have the scope ID

In vite we do this:

if (prevStyles.some((s) => s.scoped) !== nextStyles.some((s) => s.scoped)) {
needRerender = true
}

Which is truthy here since we're going from no scoped styles, to some scoped styles. So we emit a re-render message, and the client does all this correctly.

However, it seems deep in vue when it is diffing the two nodes, it never checks/realises that the previous node had no scopeId and this node does. So it never adds this new scopeId to the DOM nodes.

This means the scoped styles we successfully added simply don't apply to anything (nothing has that id in the DOM).

So yeah:

  • Should vue be diffing scopeId and adding the attribute?
  • or should vite be calling sendReload() in the check above? (that does make it work ofc)
@yyx990803
Copy link
Member

Yeah, technically it's possible to diff this, but I think this is niche enough so a reload is fine.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants