Skip to content

Commit

Permalink
fix: abort value sync if value hasn't changed
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhg committed Dec 12, 2024
1 parent 804647f commit 1590795
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/editor/src/editor/components/sync-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export const syncMachine = setup({
assertEvent(event, 'done syncing')
return context.pendingValue !== event.value
},
'pending value equals previous value': ({context}) =>
!(
context.previousValue === undefined &&
context.pendingValue === undefined
) && isEqual(context.pendingValue, context.previousValue),
},
actors: {
'sync value': syncValueLogic,
Expand Down Expand Up @@ -240,6 +245,16 @@ export const syncMachine = setup({
value: context.pendingValue ?? undefined,
}),
},
always: {
guard: 'pending value equals previous value',
actions: [
emit(({context}) => ({
type: 'done syncing',
value: context.previousValue,
})),
],
target: 'idle',
},
on: {
'update value': {
actions: ['assign pending value'],
Expand Down

0 comments on commit 1590795

Please sign in to comment.