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

useTemplateRef warning appears after rollup packaging #12852

Open
bee1an opened this issue Feb 11, 2025 · 12 comments
Open

useTemplateRef warning appears after rollup packaging #12852

bee1an opened this issue Feb 11, 2025 · 12 comments
Labels
🐞 bug Something isn't working 🔩 p2-edge-case

Comments

@bee1an
Copy link

bee1an commented Feb 11, 2025

Version

3.5.13

Reproduction link

stackblitz.com

Steps to reproduce

When the useTemplateRef argument has the same name as the variable that received it, a console warning appears after using rollup

What is expected?

No warnings

What is actually happening?

[Vue warn] Set operation on key "value" failed: target is readonly.

@KazariEX
Copy link
Contributor

KazariEX commented Feb 11, 2025

You did not configure the NODE_ENV correctly for the build script.

@yakudik
Copy link

yakudik commented Feb 11, 2025

Encountered with same warning but in usage of our UI kit.

We have a layout component (VDefaultLayoutHeader) with code

<script lang="ts" setup>
const refHeader = useTemplateRef('refHeader')
</script>

<template>
    <header ref="refHeader" class="v-default-layout-header">
        ...
    </header>
</template>

Library is building without problems, but in project where we use this component console display warning message
[Vue warn] Set operation on key "value" failed: target is readonly

@edison1105
Copy link
Member

@yakudik Please provide a minimal reproduction.

@edison1105 edison1105 added the need more info Further information is requested label Feb 12, 2025
@bee1an
Copy link
Author

bee1an commented Feb 12, 2025

You did not configure the NODE_ENV correctly for the build script.

Thanks for the answer. The same warning happens when I bundle vue as external content, although I set a fixed NODE_ENV, I know it looks weird in this example, but it really needs to be done in my project. Here's the latest example
This is not an issue when the useTemplateRef argument string is different from the variable name that is expected to be returned
like this:

Image

@edison1105
Copy link
Member

edison1105 commented Feb 12, 2025

Image
The render function returned by setup is from the production build. However, the Vue you are using is in DEV mode, so a warning is displayed.

@yakudik
The render function inside the VDefaultLayoutHeader is generated by the production build, but the Vue used in the project is in development mode. This results in a warning during development. However, after the project is built, the warning will no longer appear since everything will use the production version of Vue.

minimal reproduction with playground, the warning will disappear after changing from DEV to PROD.

@edison1105 edison1105 added 🔩 p2-edge-case and removed need more info Further information is requested labels Feb 12, 2025
@bee1an
Copy link
Author

bee1an commented Feb 13, 2025

@edison1105 Thanks for your answer. I solved my problem.

@yakudik
Copy link

yakudik commented Feb 13, 2025

@edison1105

It's true, this warning don't be showed in production, but the main problem is that we use templateRefs not only for VDefaultLayoutHeader.

We also have VDataTableTr, for example. This component has two templateRefs (on checkbox and row action)

Image

And this component, as you imagine, generate hundreds and hundreds of wirnings during local development)

@edison1105
Copy link
Member

@yakudik

<script lang="ts" setup>
-const refHeader = useTemplateRef('refHeader')
+const headerRef = useTemplateRef('refHeader') // use a diff var name is a workaround
</script>

<template>
    <header ref="refHeader" class="v-default-layout-header">
        ...
    </header>
</template>

@bee1an
Copy link
Author

bee1an commented Feb 14, 2025

@edison1105 Is this a bug? Or is it my problem?

@edison1105
Copy link
Member

@bee1an this is a bug but an edge case.

@edison1105 edison1105 added the 🐞 bug Something isn't working label Feb 14, 2025
@bee1an
Copy link
Author

bee1an commented Feb 14, 2025

@edison1105 Thank you. I look forward to your fixing it

@yakudik
Copy link

yakudik commented Feb 14, 2025

@yakudik

<script lang="ts" setup> -const refHeader = useTemplateRef('refHeader') +const headerRef = useTemplateRef('refHeader') // use a diff var name is a workaround </script> ...

Yes, and this is my current temporary solution, but i'll of course wait for this problem to be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🔩 p2-edge-case
Projects
None yet
Development

No branches or pull requests

4 participants