Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multimedia player: Fix AJAX race condition in Firefox #9329

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EricDunsworth
Copy link
Member

@EricDunsworth EricDunsworth commented May 4, 2022

Players brought in via the Data Ajax plugin sometimes tried initializing themselves twice in Firefox.

When it happened, the first attempt occurred before the AJAXed-in player had received a "wb-auto-*" ID - resulting in the player and media element's IDs getting set to "undefined" and "undefined-md" respectively.

The second attempt then treated the player's transformed HTML markup as if it was the initial markup. That caused several issues, such as a "video" class getting added to audio players (producing a large play icon overlapping the player controls), ID mismatches and a JavaScript console error related to the media variable being undefined.

This resolves it via the following changes:

  • Add a check to ensure the media variable is truthy before proceeding with initialization
  • Move most variable declarations after the media check
  • Get an ID from wb.getId() if the player doesn't already have one
    • Note: Getting an ID at this point will prevent the second initialization from occurring. But the media check is still necessary for players that use hardcoded IDs.
  • Don't check media.currentSrc in the condition that triggers renderUIEvent (speeds things up by triggering it on the first init instead of the second, higher-level media check makes this one redundant)

@EricDunsworth EricDunsworth force-pushed the multimedia-ajax-init-race-firefox branch 3 times, most recently from 3c574b1 to 03c3274 Compare May 4, 2022 22:12
Players brought in via the Data Ajax plugin sometimes tried initializing themselves twice in Firefox.

When it happened, the first attempt occurred before the AJAXed-in player had received a "wb-auto-*" ID - resulting in the player and media element's IDs getting set to "undefined" and "undefined-md" respectively.

The second attempt then treated the player's transformed HTML markup as if it was the initial markup. That caused several issues, such as a "video" class getting added to audio players (producing a large play icon overlapping the player controls), ID mismatches and a JavaScript console error related to the media variable being undefined.

This resolves it via the following changes:
* Add a check to ensure the media variable is truthy before proceeding with initialization
* Move most variable declarations after the media check
* Get an ID from wb.getId() if the player doesn't already have one
  * Note: Getting an ID at this point will prevent the second initialization from occurring. But the media check is still necessary for players that use hardcoded IDs.
* Don't check media.currentSrc in the condition that triggers renderUIEvent (speeds things up by triggering it on the first init instead of the second, higher-level media check makes this one redundant)
@EricDunsworth EricDunsworth force-pushed the multimedia-ajax-init-race-firefox branch from 03c3274 to 7979641 Compare May 10, 2022 22:10
@EricDunsworth
Copy link
Member Author

EricDunsworth commented May 13, 2022

Just got around to doing a YouTube test... seems to initialize AJAXed-in YT players twice (resulting in two sets of player controls). Will need to resolve that before promoting this PR out of draft.

@EricDunsworth
Copy link
Member Author

#9616 caught my eye. It might have an impact on the underlying issue this PR was trying to fix.

Just noting it here for whenever I get around to refocusing my attention on this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant