DEV Community

Cover image for 5 Things AI Can't Do, Even in Vue.js
DevUnionX
DevUnionX

Posted on

5 Things AI Can't Do, Even in Vue.js

This report addresses limitations AI-assisted tools encounter in Vue.js development process. Analysis of five fundamental limitations is presented in context of Vue.js's unique architecture: component composition and semantics, reactivity system and complex state flows, async behavior and lifecycle edge cases, accessibility and ARIA integration, and performance with build and toolchain compatibility. Each topic includes technical detail explanations, AI error modes, real-world examples, and code snippets.

For instance in component composition section, danger of using arrow functions in Vue components methods block is shown. Such nuances can be overlooked in AI codes, ultimately functionality breaks because this doesn't bind. In reactivity system, deep changes inside a component get automatically caught by Vue's proxy-based system. Despite this, AI assistant might skip binding reactive property using toRef for example, making state untrackable. In accessibility, Vue community emphasizes semantic HTML and recommends avoiding unnecessary ARIA roles. AI sometimes can use inappropriate combinations like div role equals button.

Table shows differences between AI and human codes in criteria like correctness, accessibility, maintainability, package size, and brand fidelity. Mermaid flow diagram created in process summarizes step by step how code from AI gets reviewed and submitted for developer approval. In conclusion, need for human supervision continues in critical concepts in Vue.js projects as well. For this study, primarily Vue.js official documents especially component fundamentals and reactivity guides and latest release notes were scanned. Then problems Vue developers encountered including GitHub issues, StackOverflow questions, and blog posts were examined. Accessibility standards with WCAG and ARIA and MDN guides were reviewed. Existing research about AI code assistant limitations like LinearB error statistics was also analyzed.

Information obtained was addressed in depth at five focus topics in context of Vue.js special details and supported with actual code examples. In each section specific error modes AI can encounter and developer strategies against them were emphasized. Vue components are designed to work nested, parent-child relationship provided with props, event emission with emits, and slot mechanisms. Semantically, developers should establish clean HTML structure, avoid unnecessary div usage. For instance wrapping a list wrongly like this breaks semantics.

Wrong with li used directly inside div. Template. Div. Li Item 1. Li Item 2. Div. Template. Correct usage is li inside ul. Semantic HTML usage and avoiding unnecessary ARIA roles is also recommended in Vue documentation. Additionally using arrow function in methods block in Vue components leads to context loss. For example: export default with methods object containing increment as arrow function. Wrong arrow function this doesn't point. This.count plus plus. In above, this reference doesn't bind correctly due to arrow function. This error is frequently made by AI. Required arrangement should be like this.

Export default. Data returning count 0. Methods object with increment function. This.count plus plus where this binds correctly here. Another point is using inter-component communication correctly. In Vue, from parent to child props, from child to parent message sent via dollar emit or defineEmits. AI sometimes misinterprets this structure, for example instead of trying to pull data from child component, might skip structures like provide/inject. Semantically too, Vue recommends using HTML5 elements directly. Don't add extra role to elements like header, nav, main because Vue documents find this unnecessary as W3C recommendation.

Developer strategies: when reviewing component codes from AI, semantic HTML rules should be checked. Component names and props should be selected clearly, value transfer with v-bind done correctly. If arrow function exists in methods in AI code should be corrected. If slot used for content transitions, placement should be correct. In parent-child communication emits and props should be set correctly. AI errors can be solved using dollar emit or defineEmits.

Vue.js reactivity system is Proxy-based and automatically catches deep changes. Changes you make in data defined with ref or reactive cause Vue component to re-render. But in some cases AI assistants can break reactivity. For instance if they directly change a reactive object's key and keep old reference, Vue might not notice. Following StackOverflow example shows this situation. Wrong with store.state.cart directly copied, reactivity cut. Import store from at store. Const cart equals store.state.cart. Cart here keeps old reference, updates not detected.

To solve this problem toRef should be used. Correct with reactive property obtained with toRef. Import toRef from vue. Const cart equals toRef store.state with cart. Now cart.value updates get tracked. In this example, if AI doesn't use toRef and does plain const cart equals store.state.cart, cart change doesn't get observed by Vue and reactivity breaks. Vue doesn't reflect state changes to DOM immediately, defers updates to next tick. Accordingly nextTick should be used. For example:

Methods object with async addItem function. This.items.push newItem. Await this.dollar nextTick. Now DOM updated, rows rendered. AI generally ignores this deferral necessity. Failure modes: AI code generators can make these errors in reactive data flow: using normal variable without using ref or reactive or wrong import, taking partial copy from reactive object like toRef example above, not seeing depth differences. Additionally when nextTick not added, problems can be experienced with DOM update timing. Real-life case is trying to access DOM elements immediately after adding to a list in a component. In this situation element hasn't been created yet because nextTick not used.

Example showing reactive state with Vue Composition API. Script setup. Import ref from vue. Const count equals ref 0. Function increment. Count.value plus plus. Script. Template. Button at click equals increment showing Increase count. Template. This code shows correct reactive usage. In AI-assisted output, wrongly writing let count equals 0 instead of ref destroys reactivity and button doesn't update number each time clicked.

Developer strategies: review reactive state definitions. Usage of ref and reactive should be applied as needed. Test by replacing normal variables in AI output with reactivity. In nested objects when change made, Vue catches but references should be extracted with functions like toRef and toRefs. nextTick should not be forgotten. Additionally to preserve performance, places where shallowReactive or markRaw needed in large data structures should be checked.

Vue.js components work according to specific lifecycle stages: beforeCreate, created, beforeMount, mounted and so on. When writing async code, this order needs watching. For instance DOM manipulation should be done inside mounted, in created stage DOM hasn't been created yet. AI sometimes makes error by trying to access DOM reference inside setup or created. In Vue data updates get processed in batches. Multiple ref.value changes happen within same tick and DOM renews in next update cycle. Therefore nextTick needed to access DOM immediately after change. AI code might not add await nextTick. For example:

Methods object with setColor function. This.color equals blue. Console.log this.dollar refs.box.style.backgroundColor. Wrong error with DOM not updated yet, shows old background. Above, because AI code didn't use nextTick, console.log can give wrong result. Async data fetching also requires attention. In Vue 3 Composition API using async await inside setup function is supported but needs managing. Especially in SSR, onServerPrefetch or in frameworks like Nuxt, asyncData usage should not be forgotten. AI generally doesn't know framework-specific options about data fetching.

Failure modes: AI assistants generally overlook timing problems. For instance might wrongly guess lifecycle and try connecting to DOM inside created instead of mounted. Watcher usage is also tricky. If async work done inside a watcher and cleanup not added, memory leak happens. In real life, developer break example: AI code setting up setInterval inside mounted without cleanup continues running even after component closes.

Developer strategies: do lifecycle validation in async operations. Review AI code and add cleanup with onMounted, onUnmounted, or watchEffect usage if needed. In server-side flows, onServerPrefetch or appropriate functions should be used. In UI updates wait for DOM to be ready with await nextTick. If subscriptions or event listeners set up in AI code, pay attention to cleanup inside beforeUnmount or onUnmounted.

In Vue projects accessibility is provided with semantic HTML and ARIA. Official Vue documentation also behaves according to W3C recommendations: use header, nav and so on, avoid extra role assignment. For instance creating navigation bar inside semantic nav is more correct than adding role equals navigation. AI codes generally don't pay attention to semantics, can make unnecessary wrapping with div and span. In Vue accessibility practices, attributes like aria-label and aria-labelledby should be emphasized. For instance if button contains only an icon, aria-label must definitely be added. AI-assisted tools can skip these gaps, creating ambiguity for screen readers. Similarly relationship of label and v-bind:id should be established solidly instead of for in Vue.

Failure modes: AI generally skips ARIA attributes or forgets role assignment when using tabindex. For instance in a modal window, title not being associated with aria-labelledby or aria-describedby is seen. On GitHub, required aria attributes deficiency was reported in a version of Vue Multiselect component. Similarly in Vue codes AI generates, aria-asterisk deficiencies can exist. On other hand, in projects created with Vue CLI or Vite, accessibility checks like eslint-plugin-vuejs-accessibility do automatic scanning. Running AI code through these checks is beneficial.

Developer strategies: adhere strictly to semantic and ARIA guides. In Vue files these should be checked: alt to img tags, label to form elements and appropriate for/id relationships should be added. Role should be given directly to custom components in AI codes if needed, for instance for elements that aren't button. Aria errors should be scanned with automatic accessibility tools like axe-core and Lighthouse. Specific to Vue, ensure optimization directives like v-once or v-memo are compatible with ARIA. If needed place additional descriptions with sr-only class. Ultimately Vue templates AI wrote should also be made ARIA compliant with human supervision.

In Vue applications bundle optimization and build configuration are important for performance. Vue official sources note APIs not needed can be removed with tree shaking. For instance if Transition component not used, gets automatically removed from package thanks to modern build tools. AI-assisted codes generally don't pay attention to packaging optimizations, for instance can import entire lodash library bloating bundle. Recommended practice is using only needed methods like import map from lodash/map.

Code splitting or lazy loading is another critical area. Separating your routes with defineAsyncComponent or dynamic import with Vue Router lightens initial load. AI generally writes code with static import and doesn't do code splitting. For instance including a large component without dynamic import causes page to load unnecessarily heavy at start. Official Vue guide draws attention to importance of this. Wrong with no dynamic import, all code loads. Import HeavyComponent from ./HeavyComponent.vue. Correct with component lazy loading. Const HeavyComponent equals defineAsyncComponent with arrow import ./HeavyComponent.vue.

Package size also grows with adding unnecessary dependencies. In Vue performance guide, importance of choosing ES module tree-shakable package is emphasized. Typical errors in AI-assisted codes: committing dist folder as source, loading in node_modules to browser, incompatible Vite/Webpack configuration. Developer strategies: review Vue CLI or Vite configurations. During build, tree-shaking and code-splitting settings should be enabled. Clean unnecessary package imports if exist in AI outputs. Check which modules are heavy using bundle analysis tools. For cached data, keep-alive or v-memo directives evaluated. Long-lived reactives that could cause memory leak in browser like watch without unsubscribing should be carefully handled. Compatibility of AI code with project rules should be validated with tests like Jest plus Vue Test Utils and profile tools.

The following table presents general comparison in Vue.js context between AI generation and human generation. Correctness low with reactivity and lifecycle errors, forgetting ref/toRef versus High compliant with Vue concepts with reactivity control done. Accessibility medium can neglect ARIA/semantics like unnecessary role versus Good with header, nav correct, alt and label complete. Maintainability low with complex structures, repeated code, missing comments especially setup API versus High using modular, readable Composition/Options API.

Package Size large with unnecessary dependencies, missing tree-shaking like all of lodash versus Small with tree-shaking and code splitting active and minimal dependencies. Brand Fidelity weak with UI/theme guide incompatible style and component usage possible versus High loyal to corporate style, using SCSS and theme systems correctly. The mermaid flowchart summarizes Vue.js development process. Developer checks component structure, props/emits usage, and slots of code from AI. Then reviews reactivity rules like ref, reactive, toRef. Compliance with async and lifecycle stages like nextTick and mounted gets checked. Finally accessibility and performance steps including tree-shaking and lazy load get evaluated.

At each stage if deficiency exists, returns and correction made. When all conditions satisfied, code approved and tested. Flowchart shows: Requirements including UI semantics, reactivity, lifecycle, performance. Get Vue code from AI. Decision whether component props/emits correct. If no make props/emits correction and return. If yes decision whether reactivity correct. If incomplete return. If complete decision whether async/lifecycle problem exists. If yes return. If no accessibility check. If incomplete return. If complete package optimization. If incomplete return. If complete code review and test approval.ms.

Top comments (0)