Skip to content

Commit

Permalink
fix: always record history on component insert
Browse files Browse the repository at this point in the history
This will result in duplicate history entries if the item has a resolveData method. This is difficult to prevent without a deferredDispatch method, similar to that being explored in #598.
  • Loading branch information
chrisvxd committed Sep 7, 2024
1 parent cfecf54 commit 09c468d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/docs/pages/docs/integrating-puck/dynamic-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const config = {
}}
/>

> When inserting components with `resolveData`, the Puck state will update twice - once for the initial insert, and once more when the method resolves, if it changes the data. This will be reflected in the undo/redo history.
### Setting fields as read-only

[`resolveData`](/docs/api-reference/configuration/component-config#resolvedatadata-params) also allows us to mark fields as read-only using the [`readOnly` parameter](/docs/api-reference/configuration/component-config#datareadonly-1).
Expand Down
6 changes: 5 additions & 1 deletion packages/core/lib/insert-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export const insertComponent = (
// Dispatch the insert, immediately
dispatch({
...insertActionData, // Dispatch insert rather set, as user's may rely on this via onAction
recordHistory: false,

// We must always record history here so the insert is added to user history
// If the user has defined a resolveData method, they will end up with 2 history
// entries on insert - one for the initial insert, and one when the data resolves
recordHistory: true,
});

const itemSelector = {
Expand Down

0 comments on commit 09c468d

Please sign in to comment.