Skip to content

Commit

Permalink
fix: ensure parent is not null on first render in resolveFields
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Jan 10, 2025
1 parent cfd21d8 commit 773a81a
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions packages/core/components/Puck/components/Fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,38 @@ const useResolvedFields = (): [FieldsType, boolean] => {
lastData,
});
},
[data, config, componentData, selectedItem, resolvedFields, state]
[data, config, componentData, selectedItem, resolvedFields, state, parent]
);

const [hasParent, setHasParent] = useState(false);

useEffect(() => {
setHasParent(!!parent);
}, [parent]);

useEffect(() => {
if (hasResolver) {
setFieldsLoading(true);
// Must either be in root zone, or have parent
if (!state.ui.itemSelector?.zone || hasParent) {
if (hasResolver) {
setFieldsLoading(true);

resolveFields(defaultFields).then((fields) => {
setResolvedFields(fields || {});
resolveFields(defaultFields).then((fields) => {
setResolvedFields(fields || {});

setFieldsLoading(false);
});
} else {
setResolvedFields(defaultFields);
setFieldsLoading(false);
});
} else {
setResolvedFields(defaultFields);
}
}
}, [data, defaultFields, selectedItem, hasResolver]);
}, [
data,
defaultFields,
state.ui.itemSelector,
selectedItem,
hasResolver,
hasParent,
]);

return [resolvedFields, fieldsLoading];
};
Expand Down

0 comments on commit 773a81a

Please sign in to comment.