fix: show the header cart badge after an add to cart - #9
Merged
Merged
Conversation
The badge renders hidden on an empty cart. After an add, WooCommerce's fragment replaced the .cart-count element, and the MutationObserver meant to reveal the badge watched the element that had just been removed: the count read 1, the badge kept its hidden class. Measured in a browser on an empty cart: count "1", class "hidden", not displayed. The badge lives in a Blade partial that decides its own visibility, included by the header and returned whole as the fragment. The observer goes. The shop spec checks the badge after an add, without a reload.
The archive add-to-cart goes through WooCommerce's own Ajax handler, not the single product form, and it is where the badge defect was seen first. The spec creates a category holding only its products, adds one from that grid and expects the badge shown with 1, without a reload. Replayed on a site: without the previous commit's fix, the badge stays hidden and the test fails.
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.
Problem (reported by the maintainer)
On an empty cart, the header badge renders with
hidden. After adding a product it stays hidden..cart-count.MutationObserverincart.jswatched the old.cart-countelement, which had just been removed from the page, so it never saw the change.Measured in a browser (pollora-test, empty cart, variation added):
hiddenhiddenThe Store API cart held the item.
Fix
parts/header/cart-badge.blade.phpholds the badge and decidesflex/hiddenitself.woocommerce_add_to_cart_fragmentsfilter returns it whole as.cart-badge.MutationObservergoes (−22 lines of JS).Test
shop.spec.ts:1.It runs in CI; pollora-test's copy of apiary doesn't have the fix.