Preserve internal comment draft across reloads#1133
Draft
unasuke wants to merge 1 commit into
Draft
Conversation
Add a `comment-draft` Stimulus controller that saves the internal comment textarea to localStorage (debounced on input) and restores it on reconnect, mirroring GitHub's issue/PR comment draft behavior. Since CommentsController redirect_backs on both success and validation failure, turbo:submit-end can't distinguish them. Clear the draft optimistically on submit-start and restore it only on a failed request (success === false), which also avoids the re-render race where a reconnected controller would otherwise restore the just-submitted text. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
59c46c3 to
982843f
Compare
Collaborator
amatsuda
added a commit
that referenced
this pull request
Jul 11, 2026
Star-rating clicks used to re-render the whole rating widget, clobbering any internal-comment draft mid-typing (the motivating gap in PR #1133's localStorage approach). The rating form now lives in a nested rating_form frame; the controller responds with Turbo Streams so each transition replaces exactly what it changes: score updates swap only the rating form, while the first rating and rating removal still replace the whole widget (they toggle the internal-comments block's visibility). A localStorage layer for true page reloads (PR #1133) remains complementary; with this change it no longer needs to compensate for in-page re-renders. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Add a
comment-draftStimulus controller that saves the internal comment textarea to localStorage (debounced on input) and restores it on reconnect, mirroring GitHub's issue/PR comment draft behavior.Since CommentsController redirect_backs on both success and validation failure, turbo:submit-end can't distinguish them. Clear the draft optimistically on submit-start and restore it only on a failed request (success === false), which also avoids the re-render race where a reconnected controller would otherwise restore the just-submitted text.
Screenshots
before
461e092a0a3ee9a6185709a078d07df2.mp4
after
13d19a0db48ad8f8ef13bed389954e19.mp4