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

fix: Fix subtitles not added to DOM region #4733

Conversation

david-hm-morgan
Copy link
Contributor

Proposed fix closes #4680

Reinstate previously removed region elements when next caption finds it is not there: Detect the absence and ensure updateDOM is true so its reinstated and the next caption can be shown.

@github-actions
Copy link
Contributor

Incremental code coverage: 85.71%

@avelad avelad added type: bug Something isn't working correctly component: TTML The issue involves TTML subtitles specifically component: captions/subtitles The issue involves captions or subtitles priority: P1 Big impact or workaround impractical; resolve before feature release labels Nov 20, 2022
@avelad avelad added this to the v4.4 milestone Nov 20, 2022
@joeyparrish joeyparrish changed the title fix: 4680 ensure DOM updated if region lost fix: Fix subtitles not added to DOM region Dec 7, 2022
Copy link
Member

@joeyparrish joeyparrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good fix overall. Thanks! If I have permission to edit, I'll make the change I suggested.

if (elemToCheck == this.textContainer_) {
return true;
}
return this.isElementUnderTextContainer_(elemToCheck.parentElement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With only one parent element, I think this could be rewritten as a while loop and be slightly more efficient that way.

https://jsbench.me/ suggests it would be 10% faster, though admittedly I did put the target element 100 levels deep in my test case.

Setup:

  const myContainer = document.createElement('div');
  let innerHTML = '<span id="myTarget"></span>';
  for (i = 0; i < 100; i++) {
    innerHTML = `<span>${innerHTML}</span>`;
  }
  myContainer.innerHTML = innerHTML;
  document.body.appendChild(myContainer);

Recursive:

function v1(thing, ancestor) {
  if (thing == null) {
    return false;
  }
  if (thing == ancestor) {
    return true;
  }
  return v1(thing.parentElement, ancestor);
}

console.log(v1(myTarget, document.body));

Loop:

function v2(thing, ancestor) {
  while (thing != null) {
    if (thing == ancestor) {
      return true;
    }
    thing = thing.parentElement;
  }
  return false;
}

console.log(v2(myTarget, document.body));

@joeyparrish joeyparrish merged commit 4081434 into shaka-project:main Dec 7, 2022
joeyparrish added a commit that referenced this pull request Dec 8, 2022
Reinstate previously removed region elements when next caption finds it
is not there: Detect the absence and ensure `updateDOM` is true so its
reinstated and the next caption can be shown.

Closes #4680

Co-authored-by: Joey Parrish <[email protected]>
joeyparrish added a commit that referenced this pull request Dec 8, 2022
Reinstate previously removed region elements when next caption finds it
is not there: Detect the absence and ensure `updateDOM` is true so its
reinstated and the next caption can be shown.

Closes #4680

Co-authored-by: Joey Parrish <[email protected]>
joeyparrish added a commit that referenced this pull request Dec 8, 2022
Reinstate previously removed region elements when next caption finds it
is not there: Detect the absence and ensure `updateDOM` is true so its
reinstated and the next caption can be shown.

Closes #4680

Co-authored-by: Joey Parrish <[email protected]>
joeyparrish added a commit that referenced this pull request Dec 8, 2022
Reinstate previously removed region elements when next caption finds it
is not there: Detect the absence and ensure `updateDOM` is true so its
reinstated and the next caption can be shown.

Closes #4680

Co-authored-by: Joey Parrish <[email protected]>
joeyparrish added a commit that referenced this pull request Dec 8, 2022
Reinstate previously removed region elements when next caption finds it
is not there: Detect the absence and ensure `updateDOM` is true so its
reinstated and the next caption can be shown.

Closes #4680

Co-authored-by: Joey Parrish <[email protected]>
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: captions/subtitles The issue involves captions or subtitles component: TTML The issue involves TTML subtitles specifically priority: P1 Big impact or workaround impractical; resolve before feature release status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EBU subtitles regression in 4.1.3 - subtitles lost: not added to region
3 participants