Fix: removing a wishlisted item from the shop sidebar shows raw JSON#543
Open
sjfgzzwd9w-maker wants to merge 1 commit into
Open
Fix: removing a wishlisted item from the shop sidebar shows raw JSON#543sjfgzzwd9w-maker wants to merge 1 commit into
sjfgzzwd9w-maker wants to merge 1 commit into
Conversation
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
Fixes #252.
Clicking the × on an item in the shop page's WISHLIST sidebar widget
(
app/components/discover_rail/shop_wishlist_widget.html.erb) submits abutton_to ... method: :deleteform. Turbo Drive intercepts this and expectsan HTML/Turbo Stream response, but
Shop::WishlistsController#destroyonlyever rendered
render json: { wishlisted: false }. Turbo can't process a bareJSON response, so it ends up displaying the raw
{"wishlisted":false}JSONinstead of removing the item from the list.
Fix
Shop::WishlistsController#destroynow responds to both formats:format.json— unchanged, still returns{ wishlisted: false }for theshop-wishlistStimulus controller'sfetch()calls (used by the startoggle on item cards).
format.turbo_stream— new, rendersturbo_stream.remove("shop_wishlist_item_#{params[:id]}"), which is whatthe sidebar widget's
button_toform now receives via Turbo Drive.discover_rail/shop_wishlist_widget.html.erb— addedid="shop_wishlist_item_<%= item.id %>"to each.shop-goals__itemso theturbo stream
removeaction has a target to remove.This is a small, additive change (
respond_to+ oneidattribute) anddoesn't touch the existing JSON path used elsewhere.
Testing
Ran the app locally via
docker compose(Rails 8.1, dev env), signed in asan existing user with an item wishlisted, and exercised the endpoint exactly
as the browser would.
Before (on
main) — Turbo-driven DELETE returns raw JSON, which Turboshows as the page body:
After (this branch) — same request now returns a turbo stream that
removes just that item:
ShopWishlistrow is deleted from the DB./shopfalls back to the "Tap the star on any item to add ithere." placeholder once the wishlist is empty.
Accept: application/json) is unaffected — still returns{"wishlisted":true}/{"wishlisted":false}.200turbo-stream no-op (no errors).AI disclosure
This PR was implemented and verified by Claude Code (Anthropic): it
identified the root cause, wrote the fix, and ran the verification steps
above (boot the app via Docker, sign in, and exercise the endpoint) against
a local dev environment.