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

Style-vars-2 v-bind feature issue when using transition and v-if #3894

Closed
Sackeys opened this issue Jun 6, 2021 · 2 comments
Closed

Style-vars-2 v-bind feature issue when using transition and v-if #3894

Sackeys opened this issue Jun 6, 2021 · 2 comments
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: sfc scope: sfc-style-vars

Comments

@Sackeys
Copy link

Sackeys commented Jun 6, 2021

Version

3.1.0-beta.7

Reproduction link

https://codesandbox.io/s/vue3-style-vars-2-issue-v-if-style-vars-binding-inside-transition-4qtf1

Steps to reproduce

Create the following component:

<template>
  <transition>
    <div v-if="isDisplayed" class="bloc"></div>
  </transition>
</template>

<script>
import { ref } from "vue"

export default {
  setup() {
    const isDisplayed = ref(false)
    const color = "#8BA7AF"

    setTimeout(() => isDisplayed.value = true, 1000)

    return {
      isDisplayed,
      color
    }
  }
}
</script>

<style scoped>
.bloc {
  width: 100px;
  height: 100px;
  background-color: v-bind(color);
}
</style>

The transition content will be displayed one second after the component was created.

What is expected?

The HTML node (transition child) should contain the style variables.

What is actually happening?

The HTML node (transition child) doesn't contain the style variables so the component is not well displayed.

sample


It doesn't work either with OptionAPI, neither with CompositionAPI.
DOM inspection:

<div id="app" data-v-app="">
    <div class="bloc" data-v-149ffcac="" style="--149ffcac-color:#9F8BAF;"> [OptionAPI] not deferred</div>
    <div class="bloc" data-v-885362c0="" style="--885362c0-color:#8BA7AF;"> [CompositionAPI] not deferred</div>
    <div class="bloc" data-v-149ffcac=""> [OptionAPI] deferred</div>
    <div class="bloc" data-v-885362c0=""> [CompositionAPI] deferred</div>
</div>
@edison1105
Copy link
Member

edison1105 commented Jun 7, 2021

as a workaround:

<template>
+   <div style="display:none">{{isDisplayed}}</div>
	<transition>
    <div v-if="isDisplayed" class="bloc">
      [CompositionAPI]
      {{ isDeferred ? "deferred" : "not deferred" }}
    </div>
  </transition>
</template>

The root cause is useCssVars called before the transition content is displayed and not re-called when subtree changed. this means the onUpdated is not called so that useCssVars is not called.
if add <div style="display:none">{{isDisplayed}}</div>, the useCssVars will be re-called when isDisplayed changed.

With Options API also not working. see https://codesandbox.io/s/vue3-style-vars-2-issue-v-if-style-vars-binding-inside-transition-forked-hum9u?file=/src/OptionsStyle.vue:152-162

@Sackeys Sackeys changed the title Style-vars-2 v-bind feature issue with CompositionAPI when using transition and v-if Style-vars-2 v-bind feature issue when using transition and v-if Jun 7, 2021
@yyx990803 yyx990803 added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label Jul 15, 2021
@yyx990803
Copy link
Member

Fixed via 6ed23f6 (will be out in 3.2)

yyx990803 added a commit that referenced this issue Jul 16, 2021
…lements change

Now uses MutationObserver to ensure it works even for HOCs

fix #3894
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: sfc scope: sfc-style-vars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants