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

calling useTemplateRef a second time for the same ref errors on prod #12754

Open
markbrockhoff opened this issue Jan 20, 2025 · 2 comments
Open
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed.

Comments

@markbrockhoff
Copy link

markbrockhoff commented Jan 20, 2025

Vue version

3.5.13

Link to minimal reproduction

https://play.vuejs.org/#__PROD__eNp9UsFOAjEU/JWXXtAEd4PoBcFEDQc9qEGOTcy6+1gK3bZpuwsJ2X/3tQtIiOHWzkynM6/dsSdjkqZGNmJjl1thPMhMlRPOvOMMHPraPHIlKqOthx3UDudYGZl5nOECWlhYXUGPHHoPXHGVa+U8CGVqP4DJmfyKs8hwdk3iE+ntRSmkKYxvIM+kFKo8j7DQFvwSwWUVgiUgo9TkXYAXhGyElPBjMVvTVWCsLrgap11VKkYbvzejHcC4EE1c0DIGCJY0jX0YSDtV2smC1fE469PM6OKFKJOV04pGugtiznJdGSHRfhgvqDRnI4hM4KiU3rxFzNsa+wc8X2K+/gdfuW3AOPu06NA2yNmR85ktkVIGevr1jltaH8lKF7Uk9QVyhk7LOmTsZM+1Kij2iS6mfY2fgZ5i7qZbj8odSoWgQdlGPWf0K14uVP+LO0zu4jmuWprid4M2eNIAh8l9Mhiy9hdCPuLj

Steps to reproduce

If you open the reproduction you can see that an error is preventing the component from being rendered. The reason for this is that the useTemplateRef is called twice for the same ref. If the second call is commented out the component renders as expected. Switching from prod mode to dev also resolves the issue by just displaying a warning instead.

What is expected?

I'd expect a second call to useTemplateRef for the same ref to behave the same on dev and prod. Ideally calling useTemplateRef twice for the same ref just results in the same object to be returned by both of them.

What is actually happening?

During dev only a warning about the second call to useTemplateRef is logged to the console. Then for the prod build an error is thrown: Cannot redefine property: input.

Any additional comments?

If it's not possible to support calling useTemplateRef twice for the same ref I'd rather have an error during dev already than only a warning. The warning is easy to miss (e.g. in my case the second call was added during rebasing and not caught by CI) and can easily break prod.

@edison1105
Copy link
Member

The development environment has already issued a warning message. Perhaps it is necessary to refine the warning message to inform users that the production environment will report an error.

@edison1105 edison1105 added the 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. label Jan 21, 2025
@markbrockhoff
Copy link
Author

Thanks for the answer, however I think just the warning isn't enough. For example in my case the second call to useTemplateRef was added while rebasing. Afterwards the app wasn't run locally again. So unless there's CI to run some test against the production build such behavior can easily break prod.
That's why I'd rather vote for having the same behavior during dev or some other way to detect this issue without having to run the app and open the dev console. Maybe it would be possible to already catch this issue when building for prod?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed.
Projects
None yet
Development

No branches or pull requests

2 participants