-
Notifications
You must be signed in to change notification settings - Fork 578
Fix event hooks not persisting across server syncs #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -594,6 +594,21 @@ function RootLayoutContent() { | |
| logger.info( | ||
| '[FAST_HYDRATE] Background reconcile: cache updated (store untouched)' | ||
| ); | ||
|
|
||
| // Selectively reconcile event hooks from server. | ||
| // Unlike projects/theme, eventHooks aren't rendered on the main view, | ||
| // so updating them won't cause a visible re-render flash. | ||
| const serverHooks = (finalSettings as GlobalSettings).eventHooks ?? []; | ||
| const currentHooks = useAppStore.getState().eventHooks; | ||
| if ( | ||
| JSON.stringify(serverHooks) !== JSON.stringify(currentHooks) && | ||
| serverHooks.length > 0 | ||
|
Comment on lines
+604
to
+605
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In conjunction with my comment on Removing this check will ensure that deleting all hooks is correctly propagated across clients. |
||
| ) { | ||
| logger.info( | ||
| `[FAST_HYDRATE] Reconciling eventHooks from server (server=${serverHooks.length}, store=${currentHooks.length})` | ||
| ); | ||
| useAppStore.setState({ eventHooks: serverHooks }); | ||
| } | ||
| } catch (e) { | ||
| logger.debug('[FAST_HYDRATE] Failed to update cache:', e); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: AutoMaker-Org/automaker
Length of output: 97
🏁 Script executed:
Repository: AutoMaker-Org/automaker
Length of output: 9928
Implement rollback in
setEventHookson server failure, or restore prior state in each handler.The
setEventHooksimplementation inapp-store.ts(lines 1418–1426) uses an optimistic-update pattern: it mutates the Zustand store immediately (set({ eventHooks: hooks })) before awaiting the server call (httpApi.settings.updateGlobal). If the server rejects the change, the catch block only logs the error and does not revert the local state.This means if the network fails or the server returns an error, the UI permanently reflects the mutation (hook deleted/toggled/added) while the server retains the original state—a divergence that persists until the next sync.
Option 1: Implement rollback in the store:
Option 2: Add explicit rollback in each component handler:
const handleDeleteHook = async (hookId: string) => { + const previousHooks = eventHooks; try { await setEventHooks(eventHooks.filter((h) => h.id !== hookId)); } catch (error) { logger.error('Failed to delete event hook:', error); toast.error('Failed to delete event hook'); + await setEventHooks(previousHooks).catch(() => {}); } };🤖 Prompt for AI Agents