feat: WebSocket flush protocol for force-save before Preview/Publish#152
Merged
Conversation
4 tasks
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
c835290 to
5a701b0
Compare
Contributor
Author
|
Branch rebuilt and force-pushed to isolate changes. This PR (
Removed from this PR: all Tests: 115 passing, 100% coverage. Lint clean. |
3 tasks
bosschaert
approved these changes
May 19, 2026
adobe-bot
pushed a commit
that referenced
this pull request
May 19, 2026
# [1.5.0](v1.4.2...v1.5.0) (2026-05-19) ### Bug Fixes * preserve pending Yjs changes across DO evictions via lastsync CF storage marker ([#153](#153)) ([defb16c](defb16c)) ### Features * adopt Cloudflare WebSocket Hibernation API ([#137](#137)) ([61e6000](61e6000)) * WebSocket flush protocol for force-save before Preview/Publish ([#152](#152)) ([8bf0ff4](8bf0ff4))
Collaborator
|
🎉 This PR is included in version 1.5.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
messageFlushRequest(type 2) andmessageFlushResponse(type 3) constants to the WebSocket protocol so the DA editor client can request an immediate force-save before Preview or Publish reads the document from da-admin.messageListener: awaitsdoc.flushSave()then sends a binary ack withok=1on success orok=0plus an error string on failure.savingPromisevariable alongside the existingsavingflag so thatflushSavecan wait for any already-in-flight PUT to complete before resolving — this prevents the ack being sent before the save actually finishes.Problem
When Preview or Publish is clicked, the client sends a flush request over the existing WebSocket connection. Without this server-side handler, the da-collab Durable Object has no way to know it should flush its debounced 2-second save early. The race is subtle: if a PUT is already in progress when
flushSaveis called, the previous code would immediately resolve, causing an ack before the in-flight save had finished.Protocol
2messageFlushRequest(client → server)3messageFlushResponse(server → client): followed byok(1=success, 0=failure) and, on failure, an error stringTest plan
messageFlushRequest sends flush response ack with ok=1 after flushSave— happy pathmessageFlushRequest sends flush response with ok=0 when flushSave throws— error path encodes error messagemessageFlushRequest works when doc has no flushSave (still sends ok ack)— graceful no-opFlush waits for an in-flight save before resolving— savingPromise race-condition fix🤖 Generated with Claude Code