[PR #32088] fix: replace sendBeacon with fetch keepalive for autosave on page close #33542

Closed
opened 2026-02-21 20:53:28 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/32088

State: closed
Merged: Yes


Summary

  • Replaces navigator.sendBeacon with fetch using keepalive: true for autosave when the user switches tabs or closes the page.
  • sendBeacon has a hard 64KB payload size limit in browsers. When workflow data exceeds this (e.g. workflows with file variables or many nodes), the autosave request silently fails, causing data loss.
  • fetch with keepalive: true provides the same fire-and-forget behavior during page unload but supports larger payloads.
  • Updated both workflow and RAG pipeline sync draft hooks, plus corresponding tests.

Changes

  • web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts - replaced sendBeacon with fetch + keepalive
  • web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.ts - replaced sendBeacon with fetch + keepalive
  • web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.spec.ts - updated tests to mock fetch instead of sendBeacon

Test plan

  • All 20 existing rag-pipeline sync draft tests pass
  • Verify autosave works on tab switch with workflows that have large payloads (>64KB)

Closes #32030

**Original Pull Request:** https://github.com/langgenius/dify/pull/32088 **State:** closed **Merged:** Yes --- ## Summary - Replaces `navigator.sendBeacon` with `fetch` using `keepalive: true` for autosave when the user switches tabs or closes the page. - `sendBeacon` has a hard 64KB payload size limit in browsers. When workflow data exceeds this (e.g. workflows with file variables or many nodes), the autosave request silently fails, causing data loss. - `fetch` with `keepalive: true` provides the same fire-and-forget behavior during page unload but supports larger payloads. - Updated both workflow and RAG pipeline sync draft hooks, plus corresponding tests. ## Changes - `web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts` - replaced `sendBeacon` with `fetch` + `keepalive` - `web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.ts` - replaced `sendBeacon` with `fetch` + `keepalive` - `web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.spec.ts` - updated tests to mock `fetch` instead of `sendBeacon` ## Test plan - [x] All 20 existing rag-pipeline sync draft tests pass - [ ] Verify autosave works on tab switch with workflows that have large payloads (>64KB) Closes #32030
yindo added the pull-request label 2026-02-21 20:53:28 -05:00
yindo closed this issue 2026-02-21 20:53:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33542