Fix/contador de caracteres travado em zero#585
Conversation
📝 WalkthroughWalkthroughThe PR refactors SmaeText.vue to support three modes: autonomous with internal useField, Field v-slot, and v-model mode. It adds local value tracking ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue (1)
76-126:⚠️ Potential issue | 🔴 CriticalFix v-model mode detection: use
vnode.propsinstead of$attrsfor declared emits.In Vue 3, event listeners for declared emits (e.g.,
update:modelValue) are excluded from$attrsby design to distinguish component events from fallthrough attributes. Since this component declaresdefineEmits(['update:modelValue']), the check'onUpdate:modelValue' in attrswill always be false, breaking the v-model/Field v-slot mode detection even when the listener is present.The suggested fix using
getCurrentInstance()?.vnode.propscorrectly accesses the listener before Vue filters it and is a practical solution commonly used for this pattern.🔧 Suggested adjustment
-import { computed, ref, useAttrs, watch } from 'vue'; +import { computed, getCurrentInstance, ref, useAttrs, watch } from 'vue'; const attrs = useAttrs(); -const modoVModel = computed(() => 'onUpdate:modelValue' in attrs); +const instance = getCurrentInstance(); +const modoVModel = computed(() => { + const vnodeProps = instance?.vnode.props ?? {}; + return 'onUpdate:modelValue' in vnodeProps; +});🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue` around lines 76 - 126, The v-model detection using useAttrs() is wrong because declared emits are removed from $attrs; change the modoVModel computed to inspect getCurrentInstance()?.vnode.props (checking for 'onUpdate:modelValue' or equivalent listener keys) instead of attrs so the component correctly detects v-model mode; update any references to modoVModel (the computed used to set standalone in useField) to rely on this new check and ensure null-safe access to vnode.props to avoid runtime errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue`:
- Around line 76-126: The v-model detection using useAttrs() is wrong because
declared emits are removed from $attrs; change the modoVModel computed to
inspect getCurrentInstance()?.vnode.props (checking for 'onUpdate:modelValue' or
equivalent listener keys) instead of attrs so the component correctly detects
v-model mode; update any references to modoVModel (the computed used to set
standalone in useField) to rely on this new check and ensure null-safe access to
vnode.props to avoid runtime errors.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
frontend/src/components/camposDeFormulario/SmaeText/SmaeText.spec.jsfrontend/src/components/camposDeFormulario/SmaeText/SmaeText.vuefrontend/src/components/camposDeFormulario/SmaeText/SmaeTextProps.tsfrontend/src/views/variaveis/CicloAtualizacao/CicloAtualizacaoModalEditar.vue



Eu não gostei do resultado. Para fazer o campo funcionar com e sem o
<Field>em volta, é preciso de uma baita salada.Summary by CodeRabbit
New Features
Bug Fixes
Tests