script/no-unstable-nested-components
Disallow component definitions inside setup or render functions.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
happy-path, ecosystem, nuxt, opinionated |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
defineComponent runs inside the parent’s setup(), creating a new Child component definition whenever that setup executes.
<script lang="ts">
import { defineComponent } from "vue";
export default { setup() { const Child = defineComponent({ render() { return null; } }); return { Child }; } };
</script>
Good
The Child definition moves to module scope, and setup() returns that existing definition instead of recreating it.
<script lang="ts">
import { defineComponent } from "vue";
const Child = defineComponent({ render() { return null; } });
export default { setup() { return { Child }; } };
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/no-unstable-nested-components": "warn"
}
},
});
Then run vp run lint.