question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested functional components break SFC CSS scoping

See original GitHub issue

Version

14.2.2

Reproduction link

https://github.com/darkylmnx/Vue-Functional-Component-CSS-Scope-Bug

Steps to reproduce

When I have nested functional components, CSS scoping seems to bug

Navigate to the page and you’ll see the bug

What is expected?

I’m expecting to see correct isolated styles image

What is actually happening?

My styles are messed up image


Ftm, I had to use only one level of functional components and this is really painful when dealing with static pages like : about pages and stuff because they only render UI and not any state so it’s unfortunate not to take advantage of functional components. Even in a more dynamic case things like the following have messed up styles.

<!-- in a page -->
<UserCard user="..." />

<!-- in a user card -->
<div>
  <UserAvatar src="props.user.img" />
  .... more markup
</div>

<!-- this doesn't work correctly -->

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:12
  • Comments:5

github_iconTop GitHub Comments

7reactions
backbone87commented, Aug 28, 2018

i encountered the same problem, but the scope is of this bug is wider. styles dont even get correctly applied if you have a normal component with scoped styles and a functional component with scoped styles as the root element inside.

i tried to locate the problem, but could only get this far, that i think it isnt a problem of vue-loader. the emitted content from build looks fine and every component gets their scope ID passed correctly. styles are also injected correctly. the problem is that some data-v-{scopeId} attributes are missing.

the problem is maybe somewhere here: https://github.com/vuejs/vue/blob/dev/src/core/vdom/patch.js#L320 where only the scopeId of the functional component is set and not that from parents.

I would recommend to reopen this issue in the vue repository.

1reaction
maksnestercommented, Sep 25, 2019

If it’s just an attribute applied to a functional component - is there a way to pass bind this id? For example we have a similar bug when class is lost when you use <template functional> in that case class can be added by accessing vue data.staticClass

<template functional>
  <div :class="['fn-class', data.staticClass || '']">

So now outside class will be correctly added. Maybe there is some similar prop where parent scoped id lives?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Discussion of Why We're Breaking Up with CSS-in-JS
CSS modules and CSS-in-JS are locally scoped by default, and you have to specifically add syntax to make things global. As much as...
Read more >
Scoped CSS - Vue Loader
With scoped , the parent component's styles will not leak into child components. However, a child component's root node will be affected by...
Read more >
how to pass style css from parent component to child ...
You can use the deep selector in scoped css block to apply the class to the component's children components. See the docs.
Read more >
React Nesting Components: Rules to Follow - Bits and Pieces
In nested components, you can also update the parent's state. This is easily accomplished in functional components by passing the set state ...
Read more >
Collected.Press
effectScope: calling off() of a detached scope should not break currentScope ... fix scoped CSS for nested nodes in functional components (4216588) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found