-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Fix/remove innerhtml #7337
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
also, that one doesn't use any user-generated content, so, there aren't any issues related to that. |
There was a problem hiding this 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.
src/js/control-bar/live-display.js
Outdated
textContent: `${this.localize('Stream Type')}\u00a0` | ||
}, { | ||
'aria-live': 'off' | ||
}); | ||
|
||
this.contentEl_.appendChild(Dom.createEl('span', { | ||
className: 'vjs-control-text' | ||
})); |
There was a problem hiding this comment.
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.
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' |
There was a problem hiding this comment.
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
in videojs-preview but not here. We can probably switch to  
here.
There was a problem hiding this comment.
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>' |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add /
textContent
const span = super.createEl('span'); | |
const span = super.createEl('span', { | |
textContent: '/' | |
}); |
className: this.buildCSSClass() | ||
}); | ||
createEl(tag = 'div', props = {}, attributes = {}) { | ||
if (!props.className) { |
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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');
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))); |
There was a problem hiding this comment.
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.
src/js/menu/menu-item.js
Outdated
while (el.firstChild) { | ||
el.removeChild(el.firstChild); | ||
} | ||
|
||
el.appendChild(createEl('span', { | ||
className: 'vjs-menu-item-text', | ||
textContent: this.localize(this.options_.label) | ||
})); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
going to do some testing with your suggestions. |
OK @gkatsev I updated this pull request with element replacements where possible. |
Thanks, seems good to me! |
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
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
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
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.