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.

vue-demi breaks composition-api template re-rendering (vue2)

See original GitHub issue

Hello @antfu ,

I am currently working on a SPA using vue2 + options-api . This SPA imports another component library (vue2 + @vue/composition-api), which simply exposes a single vue component. The component library also uses @vueuse/core using vue-demi.

Here’s an example of the exported component of the library (can not share everything since it’s an company internal project)

<template>
  <div>
    <p>FOO: {{ blub }}</p> <!-- will stay false -->
    <button @click.stop="click">CLICK ME</button>
  </div>
</template>

<script>
import { defineComponent, ref } from "@vue/composition-api"
import { useLocalStorage } from "@vueuse/core"

export default defineComponent({
  setup: (props) => {
    const foo = ref(false)

    const storageLocale = useLocalStorage("some_key", "en-GB", {
    listenToStorageChanges: true,
      window,
    })

    return {
      foo,
      click: () => {
        console.log("before click", foo.value)
        foo.value = true
        console.log("after click", foo.value) // <-- will be true
      },
    }
  },
})
</script>

So basically everything works pretty good. But as soon as I add the useLocalStorage or any other composable from @vueuse/core, the template will not re-render as soon as the button was clicked. The ref value itself works, only the template does not update. I did a lot of debugging together with my colleague, and we figured out that the template will update, as soon as we get rid of all vue-demi based code.

Dependencies of the SPA:

"dependencies": {
    "vue": "^2.6.10",
    "@company/components": "1.0.0",
    "@vue/composition-api": "1.0.0-beta.25"
},
"devDependencies": {
  ... all other
}

Dependencies of the ComponentLibrary:

"dependencies": {
   "@vueuse/core": "4.0.10"
},
"devDependencies": {
  "vue": "^2.6.10",
  "@vue/composition-api": "1.0.0-beta.25"
  ... all other
}

Do you know what could be the issue here?

Kind regards, Lukas

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lstoeferlecommented, Feb 6, 2021

Removing the packages vue and @vue/vue-composition-api resolved the issue 👍. Thanks for your help 👏

0reactions
antfucommented, Feb 5, 2021

@lstoeferle

Your snippet shows you are importing from @vue/composition-api instead of vue-demi, not sure if it’s the problem.

Can you also check the dist file to see if it bundles the code from @vue/composition-api? Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ways to force Vue to re-render a component. - Medium
Initially renderComponent is set to true, so my-component is rendered. II. Whenever we call forceRerender method, Vue will immediately set ...
Read more >
Differences Between Vue 2 And Vue 3 | by Hoang Minh Bach
Suspense is a special component that renders fallback content instead of your component until a condition is met such as a loaded backend...
Read more >
vue use
Table of contents How to use Vue 3's watch() and watchEffect() functions Using reactive() with objects in Vue 3 composition API Vue 1...
Read more >
vue 2 global properties - Mi horóscopo diario
If you are rendering a Child component, and want to set the data variables by props , you have to use both this...
Read more >
Vue.js: How to Migrate a large project from Vue 2 to Vue 3
The Vue global API has been deprecated. While it is still supported with @vue/compat , reworking your app will be required in order...
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