useVueValidNextTick (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.5 - Diagnostic Category:
lint/nursery/useVueValidNextTick - This rule has an unsafe fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/valid-next-tick
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueValidNextTick": "error" } } }}Description
Section titled “Description”Enforce valid calls to Vue’s nextTick function.
Vue updates the page some time after your data changes. nextTick lets you wait until
that update is done, either by passing it a callback function or by awaiting the Promise
it returns.
This rule reports uses of nextTick that don’t wait for the update:
nextTickis used without being called, such asnextTick.then(callback)orawait nextTick.nextTick()is called without a callback, and the returned Promise isn’t awaited, returned, assigned or chained with.then().nextTickis called with more than one argument. It only accepts one callback.nextTickis called with a callback, and the returned Promise is also awaited or chained with.then(). Use one of the two, not both.
This applies to nextTick imported from vue, Vue.nextTick, and this.$nextTick.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<script setup>import { nextTick } from "vue";
nextTick();</script>code-block.vue:4:1 lint/nursery/useVueValidNextTick FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The Promise returned by nextTick() is ignored.
2 │ import { nextTick } from "vue";
3 │
> 4 │ nextTick();
│ ^^^^^^^^
5 │ </script>
6 │
ℹ Code after this call doesn't wait for Vue to update the page, so this call has no effect.
ℹ Await the Promise, or pass a callback function to nextTick.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Add await.
4 │ await·nextTick();
│ ++++++
<script setup>import { nextTick } from "vue";
nextTick.then(() => {});</script>code-block.vue:4:1 lint/nursery/useVueValidNextTick FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ nextTick is used without being called.
2 │ import { nextTick } from "vue";
3 │
> 4 │ nextTick.then(() => {});
│ ^^^^^^^^
5 │ </script>
6 │
ℹ nextTick is a function. It only waits for Vue to update the page when it's called.
ℹ Call nextTick().
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Call nextTick.
2 2 │ import { nextTick } from "vue";
3 3 │
4 │ - nextTick.then(()·=>·{});
4 │ + nextTick().then(()·=>·{});
5 5 │ </script>
6 6 │
<script setup>import { nextTick } from "vue";
nextTick(callback, anotherCallback);</script>code-block.vue:4:1 lint/nursery/useVueValidNextTick ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ nextTick is called with more than one argument.
2 │ import { nextTick } from "vue";
3 │
> 4 │ nextTick(callback, anotherCallback);
│ ^^^^^^^^
5 │ </script>
6 │
ℹ nextTick accepts a single callback function. The other arguments are ignored.
ℹ Pass at most one callback function to nextTick.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<script>export default { async mounted() { await this.$nextTick(callback); },};</script>code-block.vue:4:11 lint/nursery/useVueValidNextTick ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ nextTick is called with a callback function, and the Promise it returns is also used.
2 │ export default {
3 │ async mounted() {
> 4 │ await this.$nextTick(callback);
│ ^^^^^^^^^^^^^^
5 │ },
6 │ };
ℹ Using both splits the code that runs after Vue updates the page into two places.
ℹ Either await the Promise, or pass a callback function to nextTick.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<script>import { nextTick } from "vue";
export default { async mounted() { await nextTick(); nextTick().then(callback); nextTick(callback); await this.$nextTick(); promise.then(nextTick); },};</script>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.