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/remove innerhtml #7337

Merged
merged 8 commits into from
Jul 28, 2021
Merged

Fix/remove innerhtml #7337

merged 8 commits into from
Jul 28, 2021

Conversation

brandonocasey
Copy link
Contributor

Description

Remove our usage of innerHTML across the board.

TODO: text-track-settings-menu which requires more changes than all of the rest of the code together. I think that will need it's own pull request.

@codecov
Copy link

codecov bot commented Jul 22, 2021

Codecov Report

Merging #7337 (e85c076) into main (b483a76) will increase coverage by 0.02%.
The diff coverage is 85.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7337      +/-   ##
==========================================
+ Coverage   79.59%   79.62%   +0.02%     
==========================================
  Files         115      115              
  Lines        7262     7277      +15     
  Branches     1745     1747       +2     
==========================================
+ Hits         5780     5794      +14     
- Misses       1482     1483       +1     
Impacted Files Coverage Δ
...-bar/audio-track-controls/audio-track-menu-item.js 3.84% <0.00%> (ø)
src/js/control-bar/seek-to-live.js 92.85% <ø> (ø)
src/js/loading-spinner.js 100.00% <ø> (ø)
src/js/menu/menu-button.js 73.80% <ø> (ø)
src/js/control-bar/spacer-controls/spacer.js 85.71% <75.00%> (-14.29%) ⬇️
src/js/button.js 62.50% <100.00%> (+1.63%) ⬆️
src/js/clickable-component.js 89.70% <100.00%> (+0.15%) ⬆️
src/js/control-bar/live-display.js 100.00% <100.00%> (ø)
...ar/playback-rate-menu/playback-rate-menu-button.js 80.70% <100.00%> (ø)
...ntrol-bar/spacer-controls/custom-control-spacer.js 100.00% <100.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b483a76...e85c076. Read the comment docs.

@gkatsev
Copy link
Member

gkatsev commented Jul 22, 2021

TODO: text-track-settings-menu which requires more changes than all of the rest of the code together. I think that will need it's own pull request.

also, that one doesn't use any user-generated content, so, there aren't any issues related to that.

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Reviewed most of these, still have audio track and subs caps menu items to review.

Comment on lines 46 to 53
textContent: `${this.localize('Stream Type')}\u00a0`
}, {
'aria-live': 'off'
});

this.contentEl_.appendChild(Dom.createEl('span', {
className: 'vjs-control-text'
}));
Copy link
Member

Choose a reason for hiding this comment

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

In here, we want the textContent Stream Type to be in the control text span. We should be careful to keep the same DOM structure before and after.

Suggested change
textContent: `${this.localize('Stream Type')}\u00a0`
}, {
'aria-live': 'off'
});
this.contentEl_.appendChild(Dom.createEl('span', {
className: 'vjs-control-text'
}));
}, {
'aria-live': 'off'
});
this.contentEl_.appendChild(Dom.createEl('span', {
className: 'vjs-control-text',
textContent: `${this.localize('Stream Type')}\u00a0`
}));

className: this.buildCSSClass(),
// No-flex/table-cell mode requires there be some content
// in the cell to fill the remaining space of the table.
textContent: '\u00a0'
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this isn't coming through here. Comparing videojs-preview to this branch's preview, I see &nbsp; in videojs-preview but not here. We can probably switch to &nbsp here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I found the issue here, the Spacer class that this inherits from did not pass along props or attributes. After correcting that this works. textContent says that it recommends not using html escape codes and instead using hex/js character codes.

@@ -18,15 +18,22 @@ class TimeDivider extends Component {
* The element that was created.
*/
createEl() {
return super.createEl('div', {
className: 'vjs-time-control vjs-time-divider',
innerHTML: '<div><span>/</span></div>'
Copy link
Member

Choose a reason for hiding this comment

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

the / here went missing in the new span. It's easy to miss.

}, {
// this element and its contents can be hidden from assistive techs since
// it is made extraneous by the announcement of the control text
// for the current time and duration displays
'aria-hidden': true
});

const div = super.createEl('div');
const span = super.createEl('span');
Copy link
Member

Choose a reason for hiding this comment

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

Add / textContent

Suggested change
const span = super.createEl('span');
const span = super.createEl('span', {
textContent: '/'
});

className: this.buildCSSClass()
});
createEl(tag = 'div', props = {}, attributes = {}) {
if (!props.className) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pass props along

}

innerHTML += '</span>';
const parentSpan = super.createEl('span', {
Copy link
Member

Choose a reason for hiding this comment

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

I think here we want to use Dom.createEl otherwise, we get a filled out li element and end up with the label inserted into the DOM twice.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, looking at el, maybe what we need to do here is to get the span that gets created and append to it?
So, not removing stuff from el on line 51/52, then parentSpan = el.querySelector('.vjs-menu-item-text');

Comment on lines 20 to 28
while (el.firstChild) {
el.removeChild(el.firstChild);
}

innerHTML += '</span>';
const parentSpan = createEl('span', {
className: 'vjs-menu-item-text'
});

parentSpan.appendChild(document.createTextNode(this.localize(this.options_.label)));
Copy link
Member

Choose a reason for hiding this comment

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

Seems like there we can do the same as for the audio track menu item. Instead of removing all children, we grab the span that's created and append to it, since it seems like it gets created as we want.

Comment on lines 72 to 79
while (el.firstChild) {
el.removeChild(el.firstChild);
}

el.appendChild(createEl('span', {
className: 'vjs-menu-item-text',
textContent: this.localize(this.options_.label)
}));
Copy link
Member

Choose a reason for hiding this comment

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

to do less work, we potentially can replace the first child with this new span and potentially do less work

el.replaceChild(createEl('span', {
  className: 'vjs-menu-item-text',
  textContent: this.localize(this.options_.label)
}, el.firstChild)

Based on the output of ClickableComponent and the expected output of MenuItem, that's the only change.

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we leave as is, but we should create an issue for this to do a follow-up refactor where we look and see where we can reduce the amount of work we're doing when creating components.

@brandonocasey
Copy link
Contributor Author

going to do some testing with your suggestions.

@brandonocasey
Copy link
Contributor Author

OK @gkatsev I updated this pull request with element replacements where possible.

@gkatsev
Copy link
Member

gkatsev commented Jul 28, 2021

Thanks, seems good to me!

@gkatsev gkatsev merged commit eb8f802 into main Jul 28, 2021
@gkatsev gkatsev deleted the fix/remove-innerhtml branch July 28, 2021 20:42
gkatsev added a commit that referenced this pull request Dec 7, 2021
In #7337, a lot of code was updated to no longer user innerHTML, but we
accidentally caused an issue with Audio Description (AD) tracks where
the track title was included twice. Once before and once after the AD
icon.

This is because we were calling `super.createEl()` but MenuItem created
a specific element and didn't just pass things the arguments along.
Instead, we should use `Dom.createEl()` directly.

Fixes #7556
gkatsev added a commit that referenced this pull request Dec 8, 2021
In #7337, a lot of code was updated to no longer user innerHTML, but we
accidentally caused an issue with Audio Description (AD) tracks where
the track title was included twice. Once before and once after the AD
icon.

This is because we were calling `super.createEl()` but MenuItem created
a specific element and didn't just pass things the arguments along.
Instead, we should use `Dom.createEl()` directly.

Fixes #7556
edirub pushed a commit to edirub/video.js that referenced this pull request Jun 8, 2023
edirub pushed a commit to edirub/video.js that referenced this pull request Jun 8, 2023
In videojs#7337, a lot of code was updated to no longer user innerHTML, but we
accidentally caused an issue with Audio Description (AD) tracks where
the track title was included twice. Once before and once after the AD
icon.

This is because we were calling `super.createEl()` but MenuItem created
a specific element and didn't just pass things the arguments along.
Instead, we should use `Dom.createEl()` directly.

Fixes videojs#7556
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.

2 participants