Skip to content

Commit 33dda7b

Browse files
author
waleed
committed
potential fix for 404 and additional logs
1 parent b5fbf6c commit 33dda7b

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

apps/sim/hooks/use-webhook-management.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,25 @@ export function useWebhookManagement({
5555
const webhookUrl = useMemo(() => {
5656
if (!webhookPath) {
5757
const baseUrl = getBaseUrl()
58-
return `${baseUrl}/api/webhooks/trigger/${blockId}`
58+
const url = `${baseUrl}/api/webhooks/trigger/${blockId}`
59+
logger.debug('Webhook URL generated using blockId fallback', {
60+
blockId,
61+
url,
62+
hasWebhookPath: false,
63+
webhookId,
64+
})
65+
return url
5966
}
6067
const baseUrl = getBaseUrl()
61-
return `${baseUrl}/api/webhooks/trigger/${webhookPath}`
62-
}, [webhookPath, blockId])
68+
const url = `${baseUrl}/api/webhooks/trigger/${webhookPath}`
69+
logger.debug('Webhook URL generated using triggerPath', {
70+
blockId,
71+
triggerPath: webhookPath,
72+
url,
73+
webhookId,
74+
})
75+
return url
76+
}, [webhookPath, blockId, webhookId])
6377

6478
const [isSaving, setIsSaving] = useState(false)
6579

@@ -81,16 +95,33 @@ export function useWebhookManagement({
8195
const currentlyLoading = store.loadingWebhooks.has(blockId)
8296
const alreadyChecked = store.checkedWebhooks.has(blockId)
8397
const currentWebhookId = store.getValue(blockId, 'webhookId')
98+
const currentTriggerPath = store.getValue(blockId, 'triggerPath')
99+
100+
logger.debug('Webhook management check', {
101+
blockId,
102+
currentlyLoading,
103+
alreadyChecked,
104+
currentWebhookId,
105+
currentTriggerPath,
106+
workflowId,
107+
})
84108

85109
if (currentlyLoading) {
110+
logger.debug('Skipping webhook fetch - already loading', { blockId })
86111
return
87112
}
88113

89114
if (alreadyChecked && currentWebhookId) {
115+
logger.debug('Skipping webhook fetch - already checked and has webhookId', {
116+
blockId,
117+
webhookId: currentWebhookId,
118+
triggerPath: currentTriggerPath,
119+
})
90120
return
91121
}
92122

93123
if (alreadyChecked && !currentWebhookId) {
124+
logger.debug('Removing from checkedWebhooks - was checked but no webhookId', { blockId })
94125
useSubBlockStore.setState((state) => {
95126
const newSet = new Set(state.checkedWebhooks)
96127
newSet.delete(blockId)
@@ -106,6 +137,7 @@ export function useWebhookManagement({
106137
return
107138
}
108139

140+
logger.debug('Starting webhook fetch', { blockId, workflowId })
109141
useSubBlockStore.setState((state) => ({
110142
loadingWebhooks: new Set([...state.loadingWebhooks, blockId]),
111143
}))
@@ -132,7 +164,24 @@ export function useWebhookManagement({
132164
const currentPath = useSubBlockStore.getState().getValue(blockId, 'triggerPath')
133165
if (webhook.path !== currentPath) {
134166
useSubBlockStore.getState().setValue(blockId, 'triggerPath', webhook.path)
167+
logger.debug('Webhook path updated from API', {
168+
blockId,
169+
oldPath: currentPath,
170+
newPath: webhook.path,
171+
webhookId: webhook.id,
172+
})
173+
} else {
174+
logger.debug('Webhook path unchanged', {
175+
blockId,
176+
path: webhook.path,
177+
webhookId: webhook.id,
178+
})
135179
}
180+
} else {
181+
logger.debug('Webhook loaded but has no path', {
182+
blockId,
183+
webhookId: webhook.id,
184+
})
136185
}
137186

138187
if (webhook.providerConfig) {

apps/sim/stores/workflows/subblock/store.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,53 @@ export const useSubBlockStore = create<SubBlockStore>()(
9797
},
9898

9999
initializeFromWorkflow: (workflowId: string, blocks: Record<string, any>) => {
100+
logger.debug('Initializing workflow values', {
101+
workflowId,
102+
blockCount: Object.keys(blocks).length,
103+
})
100104
const values: Record<string, Record<string, any>> = {}
105+
const existingWorkflowValues = get().workflowValues[workflowId] || {}
101106

102107
Object.entries(blocks).forEach(([blockId, block]) => {
103108
values[blockId] = {}
104109
Object.entries(block.subBlocks || {}).forEach(([subBlockId, subBlock]) => {
105110
values[blockId][subBlockId] = (subBlock as SubBlockConfig).value
106111
})
112+
113+
const existingBlockValues = existingWorkflowValues[blockId] || {}
114+
const hadTriggerPath =
115+
existingBlockValues.triggerPath !== undefined && existingBlockValues.triggerPath !== null
116+
const hadWebhookId =
117+
existingBlockValues.webhookId !== undefined && existingBlockValues.webhookId !== null
118+
119+
if (hadTriggerPath) {
120+
values[blockId].triggerPath = existingBlockValues.triggerPath
121+
logger.debug('Preserved triggerPath during workflow initialization', {
122+
workflowId,
123+
blockId,
124+
triggerPath: existingBlockValues.triggerPath,
125+
})
126+
}
127+
if (hadWebhookId) {
128+
values[blockId].webhookId = existingBlockValues.webhookId
129+
logger.debug('Preserved webhookId during workflow initialization', {
130+
workflowId,
131+
blockId,
132+
webhookId: existingBlockValues.webhookId,
133+
})
134+
}
135+
136+
// Log if trigger block is missing webhook state (for debugging)
137+
const blockConfig = getBlock(block.type)
138+
const isTriggerBlock =
139+
blockConfig && (blockConfig.category === 'triggers' || block.triggerMode === true)
140+
if (isTriggerBlock && !hadTriggerPath && !hadWebhookId) {
141+
logger.debug('Trigger block has no preserved webhook state', {
142+
workflowId,
143+
blockId,
144+
blockType: block.type,
145+
})
146+
}
107147
})
108148

109149
set((state) => ({

0 commit comments

Comments
 (0)