Skip to content

Commit 09c468d

Browse files
committed
fix: always record history on component insert
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.
1 parent cfecf54 commit 09c468d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

apps/docs/pages/docs/integrating-puck/dynamic-props.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const config = {
6363
}}
6464
/>
6565

66+
> 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.
67+
6668
### Setting fields as read-only
6769

6870
[`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).

packages/core/lib/insert-component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export const insertComponent = (
3535
// Dispatch the insert, immediately
3636
dispatch({
3737
...insertActionData, // Dispatch insert rather set, as user's may rely on this via onAction
38-
recordHistory: false,
38+
39+
// We must always record history here so the insert is added to user history
40+
// If the user has defined a resolveData method, they will end up with 2 history
41+
// entries on insert - one for the initial insert, and one when the data resolves
42+
recordHistory: true,
3943
});
4044

4145
const itemSelector = {

0 commit comments

Comments
 (0)