Closed Bug 2062317 Opened 3 months ago Closed 2 months ago

www.sanicare.de - Does not add products to the cart

Categories

(Core :: DOM: Core & HTML, defect, P1)

Firefox 155
Desktop
Windows 10
defect

Tracking

()

VERIFIED FIXED
158 Branch
Webcompat Priority P1
Webcompat Score 8
Tracking Status
firefox153 --- wontfix
firefox154 --- wontfix
firefox155 --- wontfix
firefox157 --- wontfix
firefox158 --- verified

People

(Reporter: ctanase, Assigned: smaug)

References

()

Details

(Keywords: webcompat:platform-bug, webcompat:site-report, Whiteboard: [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success], [wptsync upstream])

User Story

autowebcompat-repro-status:success
autowebcompat-repro-chrome-mask-fixed:false
autowebcompat-repro-channels:nightly,stable,esr
platform:windows,mac,linux,android
impact:site-broken
configuration:general
affects:all
branch:release
diagnosis-team:dom
user-impact-score:1000
autowebcompat-diagnosis-status:success

Attachments

(6 files, 2 external files)

Attached image image.png —

Environment:
Operating system: Windows
Firefox version: Firefox 153.0.3 (release)/155

Preconditions:

  • Clean profile

Steps to reproduce:

  1. Navigate to: https://www.sanicare.de/p/cationorm-sd-sine-augentropfen-30x0-4-einzeldosispipetten-09617771
  2. Click on "In den Warenkorb" to add the product to the cart.

Expected Behavior:
The product gets added to the cart.

Actual Behavior:
Nothing happens.

Notes:

  • Reproducible on the latest Firefox Release and Nightly
  • Reproducible regardless of the ETP setting
  • Works as expected using Chrome

Created from webcompat-user-report:0dc37349-1f6a-485a-8546-92e6849e8fcd

Whiteboard: [webcompat-source:product] → [webcompat-source:product][autowebcompat:processed]

Since nightly and release are affected, beta will likely be affected too.
For more information, please visit BugBot documentation.

Reproduced: this is a genuine Firefox web-compat issue on www.sanicare.de.

On the reported product page, clicking "In den Warenkorb" frequently does nothing in Firefox: the form's submit event fires, but no POST to /checkout/line-item/add is issued, no "Gute Wahl! 1 Produkt wurde hinzugefügt." confirmation appears, the header cart stays at 0,00 € and /checkout/cart is empty. Chrome, driven through the exact same steps on the same page, adds the product every single time.

The most reliable trigger is the site's own third-party newsletter pop-up ("1 von 3 Gutscheinen auswählen!", a full-viewport af2b1823.sibforms.com iframe inside #wpiam-message). While that overlay is on screen it covers the whole viewport and swallows the click in BOTH browsers (that part is not a compat difference). But after the overlay is dismissed with its own X button — at which point #wpiam-message is fully removed from the DOM in both browsers and document.elementFromPoint at the button's centre returns the button itself in both browsers — Chrome adds the product 3/3 and 5/5 times, while Firefox silently drops the add-to-cart in the majority of attempts. Firefox also fails occasionally (~1 in 4) when the button is clicked a few seconds after load without the pop-up ever being involved; it is consistently reliable only when the page has been left to settle for ~25-30 seconds. This matches the reporter's screenshot, which shows a normal-looking Firefox page with no pop-up and an empty cart after clicking.

Puppeteer confirmation script /app/repro/reproduction=huy0o_ll.mjs drives the real site (consent -> wait for pop-up -> close it via its X -> click "In den Warenkorb" -> verify the item on /checkout/cart): Firefox exits 1 (0/3 and 1/3 runs working), Chrome exits 0 (3/3 runs working).

No screenshot was taken because the breakage is a broken interaction, not a layout/rendering problem.

User Story: (updated)
Whiteboard: [webcompat-source:product][autowebcompat:processed] → [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success]
User Story: (updated)

They also show a warning and recommending people to use Firefox.

Severity: -- → S2
User Story: (updated)
Webcompat Priority: --- → P1
Webcompat Score: --- → 9
Priority: -- → P1
Webcompat Score: 9 → 8
Whiteboard: [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success] → [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success][autwebcompat:diagnose]
Whiteboard: [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success][autwebcompat:diagnose] → [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success][autowebcompat:diagnose]
Whiteboard: [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success][autowebcompat:diagnose] → [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success]
Whiteboard: [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success] → [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success][autowebcompat:diagnose]

Root cause analysis generated by autowebcompat bot:

The site's add-to-cart is dropped because a Shopware plugin registration is torn down by a setTimeout(..., 0) before Shopware's DOMContentLoaded handler gets a chance to instantiate it — and in Firefox that 0 ms timer task runs before DOMContentLoaded is dispatched, whereas in Chrome DOMContentLoaded is dispatched first.

Mechanism, in the deferred theme bundle https://www.sanicare.de/s3/theme/…/js/all.js:

  1. Shopware core registers, at module-evaluation time, document.addEventListener("DOMContentLoaded", () => PluginManager.initializePlugins(), false). initializePlugins() walks the plugin registry and instantiates every plugin that is registered at that moment (with window.Feature.isActive("v6.6.0.0") === false on this shop, that walk is fully synchronous).

  2. Later in the same bundle, the shop's own "ebiOffcanvas" module runs a function (minified q). Because all.js is a defer script, document.readyState is already "interactive" when it runs, so the branch "loading" === document.readyState ? addEventListener("DOMContentLoaded", q) : q() executes q() immediately. q():

    • deregisters the core OffCanvasCart plugin and re-registers its own subclass for [data-off-canvas-cart] and [data-offcanvas-cart];
    • overrides AddToCart with a subclass whose redirectTo is frontend.cart.custom-offcanvas;
    • installs a delegated document-level submit handler:
      document.addEventListener("submit", function (t) {
        if (t.defaultPrevented) return;
        const e = t.target;
        if (!e.hasAttribute("data-add-to-cart")) return;
        t.preventDefault();
        const s = A.getPluginInstances("OffCanvasCart");
        if (null == s || !s.length) return;          // <-- silent early return
        const n = new FormData(e); n.delete("redirectTo"); n.delete("redirectParameters");
        s.forEach(t => t.openOffCanvas(e.getAttribute("action"), n, null));
      });
      
    • and finally schedules the teardown of those registrations: setTimeout(() => { deregister("OffCanvasCart", "[data-offcanvas-cart]"); deregister("OffCanvasCart", "[data-off-canvas-cart]"); deregister("OffCanvasCart"); }, 0).

So the code implicitly assumes that DOMContentLoaded (and therefore initializePlugins()) runs before the already-scheduled 0 ms timer. That assumption holds in Chrome, which dispatches DOMContentLoaded in the same task in which the last deferred script finishes, before yielding to expired timers. In Firefox the expired 0 ms timer task is run while the event loop is spun over the remaining deferred scripts, i.e. before DOMContentLoaded is dispatched (which the HTML spec does via a separately queued task). Consequently in Firefox OffCanvasCart is already deregistered when initializePlugins() runs, no OffCanvasCart instance is ever created, and both the delegated submit handler above and the overridden AddToCart plugin (_openOffCanvasCarts() iterates getPluginInstances("OffCanvasCart")) call preventDefault() and then do nothing: the submit event fires, the native POST is suppressed, and no XHR to /checkout/line-item/add is ever issued. Nothing about the newsletter overlay, click interception, or ETP is involved — the overlay only shifts timing, which is why the failure looks intermittent (whenever DOMContentLoaded happens to land in the same task as the deferred bundle, Firefox works too).

This is a race the site loses in Firefox, not a Firefox API gap: Firefox's ordering is the spec-conformant one (DOMContentLoaded is fired from a queued task), and Chrome's earlier dispatch is what accidentally makes the site work.

Evidence:

A. Live-site divergence isolated to one plugin instance (Firefox DevTools vs Chrome DevTools, same URL, consent accepted):

  • Firefox: PluginManager.getPluginInstances("OffCanvasCart") → length 0; document.querySelector("[data-offcanvas-cart]").__plugins → empty.
  • Chrome: 1 instance, options {… additionalOffcanvasClass: "custom-cart-offcanvas", offcanvasPosition: "right" …} (i.e. the shop's custom subclass).
  • Both browsers identical for the neighbours: AddToCart → 3 instances (subclass with redirectTo: "frontend.cart.custom-offcanvas", so the shop's override did run), CartWidget → 1 instance, registration [data-add-to-cart] present.

B. The code path that silently drops the click (read out live from the page, and from the minified bundle):

  • AddToCart._formSubmit → t.preventDefault(); … this._openOffCanvasCarts(action, serialize(form))
  • AddToCart._openOffCanvasCarts → const s = PluginManager.getPluginInstances("OffCanvasCart"); iterate(s, …) — an empty list means nothing is sent.
  • The ebi delegated document submit handler has the explicit if (null == s || !s.length) return; after t.preventDefault().
  • PluginManager.initializePlugins() only instantiates plugins that have live entries in registrations; window.Feature.isActive("v6.6.0.0") is false on this shop, so no await happens and the walk is synchronous.

C. Ordering instrumented before any page script ran (Puppeteer evaluateOnNewDocument hooking window.PluginManager's setter and wrapping register/deregister/initializePlugins, plus wrapping document.addEventListener("DOMContentLoaded", …)), /app/diagnosis/probe.mjs:

Firefox (ms since navigation start):

646  interactive  PluginManager assigned
668  interactive  register OffCanvasCart [data-offcanvas-cart]      (core)
669  interactive  addEventListener DOMContentLoaded ()=>l.Z.initializePlugins()
681  interactive  deregister/register OffCanvasCart …               (ebi q() runs inline)
704  interactive  deregister OffCanvasCart x3   <-- the setTimeout(0) teardown FIRES HERE
757  interactive  >> DCL listener start ()=>l.Z.initializePlugins()
757/799/810      initializePlugins() CALLED  (asyncRegs=0)
825  interactive  DCL done, OCC=header-cart{none}
1880 complete     timeout1000 after DCL, OCC=header-cart{none}
final: header-cart{none}, Feature v6.6=false, ebiOffcanvasConfig={"active":true}

Chrome:

1097   interactive  PluginManager assigned
1114   interactive  register OffCanvasCart [data-offcanvas-cart]
1139   interactive  deregister/register OffCanvasCart …  (ebi q() runs inline)
1143   interactive  >> DCL listener start ()=>l.Z.initializePlugins()
1187   interactive  DCL done, OCC=header-cart{OffCanvasCart}
1242   interactive  deregister OffCanvasCart x3   <-- setTimeout(0) teardown fires AFTER init
final: header-cart{OffCanvasCart}

Identical script order, identical registrations, asyncRegs=0 in both — the only difference is that Firefox ran the expired 0 ms timer at 704 ms, 53 ms before DOMContentLoaded was dispatched at 757 ms, while Chrome dispatched DOMContentLoaded 3.5 ms after the deferred bundle and only ran the timer 100 ms later. (In an earlier Firefox run the timer happened to fire at 1050 ms, i.e. after init — the same race the report describes as intermittent.)

D. Causal link to the reported symptom (/app/diagnosis/probe2.mjs, real page, overlay removed, real click on #productDetailPageBuyProductForm button.btn-buy, network sniffed for /checkout/line-item/add):

firefox run1: OffCanvasCartInstance=[none]          addRequestSent=false
firefox run2: OffCanvasCartInstance=[none]          addRequestSent=false
firefox run3: OffCanvasCartInstance=[none]          addRequestSent=false
chrome  run1: OffCanvasCartInstance=[OffCanvasCart] addRequestSent=true
chrome  run2: OffCanvasCartInstance=[OffCanvasCart] addRequestSent=true
chrome  run3: OffCanvasCartInstance=[OffCanvasCart] addRequestSent=true

Perfect 1:1 correlation between "an OffCanvasCart instance exists" and "the add-to-cart POST is sent". No page errors explain it: Firefox logs 4× Error: Element not found from initializePlugins()'s error collector but Chrome logs the same 4 errors too (Uncaught (in promise) Error: Element not found), so they are not the differentiator.

E. Reduced testcase /app/diagnosis/testcase=7b96mdwt.html, loaded from file:// in both browsers:

  • Firefox: order = ["deferred script 1 ran, document.readyState=interactive", "deferred script 2 ran", "setTimeout(0) callback: deregister OffCanvasCart (registry cleared)", "DOMContentLoaded: PluginManager.initializePlugins()"], timerRanBeforeDOMContentLoaded=true, instances=0; clicking the orange "In den Warenkorb" button → "ADD TO CART SILENTLY DROPPED (Firefox behaviour)".
  • Chrome: order = ["deferred script 1 ran, document.readyState=interactive", "deferred script 2 ran", "DOMContentLoaded: PluginManager.initializePlugins()", "-> instantiated OffCanvasCart on [data-offcanvas-cart]", "setTimeout(0) callback: deregister OffCanvasCart (registry cleared)"], timerRanBeforeDOMContentLoaded=false, instances=1; clicking the button → "ADD TO CART WORKED (Chrome behaviour)".
    The testcase reproduced deterministically on every load in both browsers.
User Story: (updated)
Whiteboard: [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success][autowebcompat:diagnose] → [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success]

Root cause analysis generated by autowebcompat bot:

Firefox runs an expired setTimeout(0) task before firing DOMContentLoaded; Chrome fires DOMContentLoaded first. In the deferred bundle all.js an ebi offcanvas module synchronously re-registers OffCanvasCart and overrides AddToCart, then calls setTimeout(deregister, 0), while the storefront instantiates plugins on DOMContentLoaded. Chrome creates the OffCanvasCart instance, Firefox never does. Both submit handlers call preventDefault then return silently when there are zero instances, so no POST to checkout line-item add is sent and the cart stays at 0,00 EUR.

Evidence:

PluginManager hooks, 5 loads each. Firefox 5 of 5: register 1449ms, setTimeout(0) deregister 1450ms, DOMContentLoaded plus initializePlugins 1507ms, 0 instances. Chrome 5 of 5: register 2737ms, DOMContentLoaded plus initializePlugins 2740ms, 1 instance, deregister 2815ms. Timer stack q() in all.js line 37. Firefox click with button topmost: submit defaultPrevented, no line-item add request, total 0,00 EUR, no errors. Creating one instance by hand made the next click POST line-item add and the total became 14,95 EUR. Testcase: Firefox FAIL, Chrome PASS.

Attached file Minimal test-case. —

Firefox logs:

DEFER
timeout
DCL inline
DCL

Chrome / WebKit:

DEFER
DCL inline
DCL
timeout

It seems we're resolving DOMContentLoaded async, which makes the timeout fire first. But if we're running the defer scripts at that point, firing DOMContentLoaded sync seems fine...

User Story: (updated)

We've had the more async behavior for normal Documents since https://bugzilla.mozilla.org/show_bug.cgi?id=344305.
Just backing out that ancient change would likely lead to similar crashes. But we could possibly use end-of-task model. Hmm, though, needs testing when promises are resolved in the other browsers, before or after DOMContentLoaded.

(Did the site work when we had still deferred setTimeout?)

(https://bugzilla.mozilla.org/show_bug.cgi?id=445330 changed behavior for data documents, but those are simple.)

nsContentUtils::RunInStableState wouldn't work here, since we aren't allowed to dispatch DOM events there (for good reasons).

Hmm, I can't reproduce the issue on the site.

Your WIP patch fixes the problem for me.

The patch does cause tons of test failures.

Oh, found, https://wpt.fyi/results/html/syntax/parsing/DOMContentLoaded-defer.html?label=master&label=experimental&aligned&q=DOMContentLoaded-defer.html
There is even a test to check that what Gecko does is right.

Edit. Or that either behavior is fine.

https://github.com/web-platform-tests/wpt/pull/2479 is what added that test, for what is worth.

https://html.spec.whatwg.org/multipage/parsing.html#the-end step 6 always fires DOMContentLoaded off a task, so we should probably fix the spec if we're changing this.

The question is how. The ordering of tasks isn't guaranteed. Maybe we could remove that one task, and add another task later? Though, timeout might still run at random place.

Assignee: nobody → smaug
Attachment #9631402 - Attachment description: WIP: Bug 2062317, be more synchronous with DOMContentLoaded → Bug 2062317, be more synchronous with DOMContentLoaded, r=#dom-core
Status: NEW → ASSIGNED
Attachment #9631402 - Attachment description: Bug 2062317, be more synchronous with DOMContentLoaded, r=#dom-core → WIP: Bug 2062317, be more synchronous with DOMContentLoaded, r=#dom-core
Attachment #9631402 - Attachment description: WIP: Bug 2062317, be more synchronous with DOMContentLoaded, r=#dom-core → Bug 2062317, be more synchronous with DOMContentLoaded, r=#dom-core

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/62568 for changes under testing/web-platform/tests

Whiteboard: [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success] → [webcompat-source:product][autowebcompat:processed][autowebcompat:repro-success], [wptsync upstream]
Pushed by smolnar@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/5dfbbf94603e https://hg.mozilla.org/integration/autoland/rev/00289483bd3e Revert "Bug 2062317, be more synchronous with DOMContentLoaded, r=farre" for causing mochitest failures @ browser_about_restricted.js

also these xpc failures

Upstream PR was closed without merging

Regressions: 2071769
Attachment #9631402 - Attachment description: Bug 2062317, be more synchronous with DOMContentLoaded, r=#dom-core → Bug 2062317, be more synchronous with DOMContentLoaded, r=farre
Pushed by asilaghi@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/034f39744d1e https://hg.mozilla.org/integration/autoland/rev/2626438fb4db Revert "Bug 2062317 - Fix tests that synthesize input before the window is positioned, r=farre" for causing build bustages

Backed out for causing build bustages
Backout Link
Push with failures
Failure Log

Upstream PR was closed without merging

Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch

Upstream PR merged by moz-wptsync-bot

Regressions: 2074455
Regressions: 2076109
Component: Site Reports → DOM: Core & HTML
Flags: needinfo?(smaug)
Product: Web Compatibility → Core
Flags: in-testsuite+

Verified as FIXED using the RC Build

Tested with:

Browser / Version: Firefox 158.0-candidate build 2
Operating System: Windows 10 PRO x64

Status: RESOLVED → VERIFIED
Regressions: 2089523
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: