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

Add rule to warn against DOM queries in computed #2531

Open
panstromek opened this issue Aug 17, 2024 · 0 comments
Open

Add rule to warn against DOM queries in computed #2531

panstromek opened this issue Aug 17, 2024 · 0 comments

Comments

@panstromek
Copy link

panstromek commented Aug 17, 2024

Please describe what the rule should do:

I've just reviewed a piece of code with DOM queries in computed prop. This is subtly wrong, because the computed is not recomputed when DOM changes. The right way to do this is to either use ref binding in template or query the DOM in event handlers where the element is needed.

What category should the rule belong to?

[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

const current = ref(0)
// following computed is only updated when `current` changes, but not when DOM changes
const currentPostElement = computed(() => document.querySelectorAll('post')[current.value])
@panstromek panstromek changed the title Add rule to warn agains DOM queries in computed Add rule to warn against DOM queries in computed Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant