Skip to content

Commit

Permalink
fix: refactored updating meta to use watchEffect
Browse files Browse the repository at this point in the history
 due to issue similar to watchEffect logaretm#3580
  • Loading branch information
zaalbarxx committed Nov 29, 2023
1 parent 88ad658 commit 2b62bab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/vee-validate/src/FieldGroup.ts
Expand Up @@ -21,7 +21,7 @@ const FieldGroupImpl = /** #__PURE__ */ defineComponent({

function slotProps() {
return {
meta: meta.value,
meta,
};
}

Expand Down
17 changes: 13 additions & 4 deletions packages/vee-validate/src/useFieldGroup.ts
@@ -1,14 +1,14 @@
import {
computed,
inject,
markRaw,
onBeforeUnmount,
provide,
ref,
Ref,
toValue,
ComputedRef,
MaybeRefOrGetter,
reactive,
watchEffect,
} from 'vue';
import {
FieldContextForFieldGroup,
Expand All @@ -19,7 +19,7 @@ import {
import { FieldGroupContextKey } from './symbols';

interface FieldGroupComposable {
meta: ComputedRef<FieldGroupMeta>;
meta: FieldGroupMeta;
fields: Ref<FieldContextForFieldGroup[]>;
groups: Ref<FieldGroupContextForParent[]>;
}
Expand All @@ -31,7 +31,7 @@ export const useFieldGroup = (checkChildFieldGroups: MaybeRefOrGetter<boolean> =
const providerContext: PrivateFieldGroupContext = { fields, groups };
provide(FieldGroupContextKey, providerContext);

const meta = computed<FieldGroupMeta>(() => {
const calculateMeta = (): FieldGroupMeta => {
const checkChildGroups = toValue(checkChildFieldGroups);
const groupsMeta = {
valid: checkChildGroups ? groups.value.every((f: FieldGroupContextForParent) => toValue(f.meta).valid) : true,
Expand All @@ -58,6 +58,15 @@ export const useFieldGroup = (checkChildFieldGroups: MaybeRefOrGetter<boolean> =
validated: groupsMeta.validated && fieldsMeta.validated,
pending: groupsMeta.pending || fieldsMeta.pending,
};
};

const meta = reactive(calculateMeta());

watchEffect(() => {
const newMeta = calculateMeta();
for (const key in newMeta) {
meta[key as keyof FieldGroupMeta] = newMeta[key as keyof FieldGroupMeta];
}
});

if (parentFieldGroup) {
Expand Down

0 comments on commit 2b62bab

Please sign in to comment.