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

When using pug lang in templates data state get's wiped out when updating a .vue Single File Component with Reactivity Transform #455

Closed
JordashTalon opened this issue Aug 11, 2023 · 13 comments
Labels

Comments

@JordashTalon
Copy link

JordashTalon commented Aug 11, 2023

Having a strange issue when using pug with reactivity transform macro.

If you have a simple template like this:

<template lang="pug">
.pageWrapper
  p Variable should show here: #[b {{value}}]
  p Change text here to something else
</template>

<script setup>
let value = $ref('Value here');
</script>

And a nuxt.config.ts like this:

import ReactivityTransform from '@vue-macros/reactivity-transform/vite';

export default defineNuxtConfig({
  vite: {
    plugins: [ReactivityTransform()],
  },
  devtools: { enabled: true },
});

First time you load the page it renders perfectly fine. But if you change the template then it seems to wipe out the data. See screenshots below:

image

If you change the template the data disappears during hot module reload:

image

Any ideas on a fix for this? It works fine without using Pug, but we use Pug extensively for development.

One side note, before using the Vue Macro we used reactivity transform like this:

export default defineNuxtConfig({
  vite: {
    vue: {
     reactivityTransform: true
   }
  }
});

And it worked fine, but Vue is removing that way of using Reactivity Transform.

Here is a minimum reproducible project:
https://stackblitz.com/edit/github-17oxys?file=pages%2Findex.vue

@stackblitz
Copy link

stackblitz bot commented Aug 11, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@JordashTalon JordashTalon changed the title When using pug lang in templates data state get's wiped out when updating a .vue Single File Component When using pug lang in templates data state get's wiped out when updating a .vue Single File Component with Reactivity Transform Aug 11, 2023
@sxzz sxzz added the upstream label Aug 11, 2023
@sxzz
Copy link
Member

sxzz commented Aug 11, 2023

The bug is because of @vitejs/plugin-vue. Trying to fix it.

@JordashTalon
Copy link
Author

The bug is because of @vitejs/plugin-vue. Trying to fix it.

Thanks a ton!

@sxzz
Copy link
Member

sxzz commented Aug 12, 2023

Let's track vitejs/vite-plugin-vue#232

@so1ve
Copy link

so1ve commented Aug 19, 2023

Out of topic: @JordashTalon There is an official nuxt integration for vue-macros so you don't have to setup the vite plugin manually

@JordashTalon
Copy link
Author

@so1ve I think my example is using the official nuxt integration for Vue-macros? Or am I implementing it wrong?

@so1ve
Copy link

so1ve commented Aug 19, 2023

Ah! I see, you are using a separate package (reactivity-transform), not the whole vue-marcos

@JordashTalon
Copy link
Author

I'll try it with the nuxt vue macros integration, I wonder if that will fix it?

@JordashTalon
Copy link
Author

JordashTalon commented Aug 19, 2023

I tested the nuxt integration docs from here: https://vue-macros.sxzz.moe/guide/nuxt-integration.html

Unfortunately that does not solve the problem😭

@sxzz
Copy link
Member

sxzz commented Aug 21, 2023

Fixed, please upgrade to @vitejs/plugin-vue@4.3.2.

@sxzz sxzz closed this as completed Aug 21, 2023
@JordashTalon
Copy link
Author

@sxzz If i'm using the Reactivity Transform Macro here: https://vue-macros.sxzz.moe/features/reactivity-transform.html how would I upgrade the vitejs plugin? I think it's added as a dependency to that module? Or should I manually install 4.3.2 as a new dependency?

@JordashTalon
Copy link
Author

Actually it worked! I just did npm install @vitejs/plugin-vue@4.3.2 and it started working perfectly, thanks!

I'm wondering if the modules listed on these pages:
https://vue-macros.sxzz.moe/features/reactivity-transform.html
https://vue-macros.sxzz.moe/guide/nuxt-integration.html

Should be updated to automatically use that version of plugin-vue ?

@sxzz
Copy link
Member

sxzz commented Aug 22, 2023

I'm not familiar to npm itself (I'm using pnpm). Since you're using Nuxt with Vite integration and it's unrelated to Vue Macros. So I don't think writing down into Vue Macros docs is suitable. Maybe npm upgrade @vitejs/plugin-vue could be helpful, instead of installing a new dep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants