Skip to content

Slots are mixing up when component gets updated #968

@fylica

Description

@fylica

Reporting a bug?

I'm using this example to apply custom formatting for currency value.

<script setup>
import { computed } from 'vue'

const props = defineProps({
  amount: {
    type: [String, Number],
    default: 0,
  },
})

const amountFloat = computed(() => parseFloat(props.amount) / 100)
</script>

<template lang="pug">
i18n-n(:value='amountFloat', format='currency')
  template(#currency='slotProps')
    .text-h6 {{ slotProps.currency }}
  template(#group='slotProps')
    .text-subtitle1.self-end {{ slotProps.group }}
  template(#integer='slotProps')
    .text-h3 {{ slotProps.integer }}
  template(#decimal='slotProps')
    .text-subtitle1 {{ slotProps.decimal }}
  template(#fraction='slotProps')
    .text-subtitle1 {{ slotProps.fraction }}
</template>

It renders the integer part ok on initial render when the amountFloat is => 1000, but if component gets updated with some bigger number, the second integer part will not uses the #integer slot's class, but it rather uses the class of #fraction slot.

Expected behavior

All integer sections uses the classes defined within the integer slot.

Reproduction

https://codesandbox.io/s/youthful-grothendieck-99wfxv?file=/src/components/FormattedPrice.vue

Just use input to change formatted value.

System Info

System:
    OS: macOS 12.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 4.36 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.6.1 - ~/.nvm/versions/node/v16.6.1/bin/node
    Yarn: 1.22.18 - ~/.yarn/bin/yarn
    npm: 7.20.5 - ~/.nvm/versions/node/v16.6.1/bin/npm
  Browsers:
    Chrome: 100.0.4896.60
    Safari: 15.3

Screenshot

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions