Fix race between auto-save and publish on Cmd+Enter#2895
Conversation
When the user types a title and immediately presses Cmd+Enter on a new draft, the publish request can reach the server before the auto-save PATCH commits the title. The before_save callback in Card sets the title to "Untitled" (since title was still nil in memory), and the late PATCH rewrites it to the typed value — but the intermediate state generates a phantom card_title_changed event, a system comment "changed the title from Untitled to ...", and a webhook delivery as side effects. Fix by adding an optional auto-save outlet to clicker_controller. When wired up via clicker_auto_save_outlet="#card_form", clicker awaits the auto-save submit before triggering the publish click. The change is backwards-compatible: clicker without the outlet behaves as before. Closes basecamp#2778
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition where publishing a brand-new draft via Cmd/Ctrl+Enter could reach the server before the draft’s auto-save PATCH, causing a transient "Untitled" title and related phantom side effects (events, system comments, webhook deliveries). The fix makes the publish hotkey wait for the draft auto-save to complete before triggering the publish action.
Changes:
- Add an optional
auto-saveStimulus outlet toclicker_controllerand await the outlet’ssubmit()before clicking. - Wire
clicker_auto_save_outlet="#card_form"on the “Create card” and “Create and add another” buttons so hotkey-triggered publish waits for auto-save. - Add a system test that reproduces the race (via an artificial delay) and asserts no phantom title-change artifacts are created.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
app/javascript/controllers/clicker_controller.js |
Await auto-save (via optional outlet) before triggering the click action used by hotkeys. |
app/views/cards/container/footer/_create.html.erb |
Provide the auto-save outlet hookup for the create/publish buttons on draft creation. |
test/system/card_creation_race_test.rb |
System-level regression test for the Cmd/Ctrl+Enter publish race and its side effects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| async click() { | ||
| if (this.hasAutoSaveOutlet) { | ||
| await this.autoSaveOutlet.submit() |
|
Closing as duplicate of #2812 (which was opened first). See my comment there. |
Summary
When the user types a title and immediately presses Cmd+Enter on a new draft, the publish request can reach the server before the auto-save PATCH commits the title. The
before_savecallback inCardthen writes"Untitled"(sincecard.titleis stillnilin memory), and the late PATCH overwrites it with the typed value. The intermediate state has several visible side effects:card_title_changedevent is recorded.card_title_changeddelivery."Untitled"until the Turbo Stream broadcast from the late PATCH replaces it — which is why the bug is hard to notice on fast setups but stuck-visible on slow self-hosted instances (Incomplete card title when a new card is saved with Cmd+Enter keyboard shortcut #2778).Fix
Add an optional
auto-saveoutlet toclicker_controller. When wired up viaclicker_auto_save_outlet="#card_form"on the Create card / Create and add another buttons,clickerawaits the auto-save submit before triggering the publish click. Backwards-compatible:clickerwithout the outlet behaves exactly as before.Reproduction
Adding
sleep 0.6toCardsController#updatewidens the race window and reliably reproduces the bug. The included system test uses the same technique.Test plan
test/system/card_creation_race_test.rb— TDD-validated (fails onmain, passes with this commit).card_title_changedevent, no"changed the title from..."system comment.bin/ci).Prior art
@LuisMSAmorim outlined the same root cause and proposed a similar outlet-based approach in #2362; this PR extends that analysis with a reliable repro and documents the data-pollution side effects.
Closes #2778