Open Bug 1905223 Opened 3 months ago Updated 3 months ago

Figure out why, on some systems, Onboarding::_addScriptsAndRender is able to run twice per sidebar even when the event listener has `once: true`

Categories

(Firefox :: Messaging System, task, P3)

task

Tracking

()

People

(Reporter: aminomancer, Unassigned)

References

Details

Punam and I found a mysterious phenomenon while working on bug 1900486. For me, on Windows 10, it was necessary to remove once: true from this event listener to make Onboarding render the opt-in message after having previously seen a survey in the same sidebar. Without once: true, if you view the survey, "Turn off Review Checker," then reopen the sidebar with the urlbar button, it will just show a blank sidebar. This is because, although the RenderWelcome event is dispatched by AboutWelcomeShoppingChild, there is no event listener to hear that event, as the event listener removed itself after showing the opt-in message (due to once: true).

But when Punam tested the same thing, instead of showing a blank sidebar, it correctly showed the opt-in message. It's mysterious because the event listener should have been removed after showing the first message, making it impossible to render 2 messages in the same sidebar. And that event listener can't have been re-added, because it's only added in Onboarding's constructor, which has no consumers. The only thing that calls the constructor is the file itself, as part of the file's side effects. So that event listener can only be added once per load of onboarding.mjs. Yet, onboarding.mjs is only loaded by one file: shopping.html. It just has a script tag. That means the only way it could be added twice is if shopping.html was reloaded. But it doesn't seem like shopping.html was reloaded, because that would also cause the whole DOM to reset, which didn't seem to happen.

So this is quite strange and I'd like if we could test this on multiple systems to see if it can be reproduced. It could have been anything, from a mere build issue in Punam's local environment, to a lower-level bug with event listeners. So testing this on other environments would be helpful. All you have to do to test it is make sure you have bug 1900486's patch (should land on m-c soon), then go to onboarding.mjs and add back once: true to the event listener. Then follow these steps:

  1. Run Firefox on a new profile
  2. Set these prefs:
    browser.shopping.experience2023.enabled=true
    browser.shopping.experience2023.autoOpen.enabled=true
    
  3. Go to amazon and find a product page so the sidebar opens. Opt in to RC via the opt-in message in the sidebar.
  4. Close the amazon tab
  5. Go to about:config
  6. Set these prefs:
    browser.shopping.experience2023.survey.optedInTime=1696550403
    browser.shopping.experience2023.survey.pdpVisits=5
    
  7. Go to about:profiles and click "Restart normally..."
  8. Having restarted Firefox, go to amazon.com and find a product page again
  9. The sidebar should show, and a survey should be visible
  10. Complete the survey and quickly, when the green thank you card appears, scroll down to Settings, expand it, and click "Turn off Review Checker"
  11. A feature callout should show; dismiss it
  12. Click the urlbar shopping button the feature callout was anchored to, to reopen the sidebar
  13. The sidebar should now be empty, except perhaps for the thank you card (which should disappear after 5 seconds) depending on your speed
  14. This is the point of divergence, where for me the sidebar is empty but for Punam it shows the opt-in message
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.