-
Notifications
You must be signed in to change notification settings - Fork 185
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
[Bug] e.querySelectorAll(...).forEach is not a function #2099
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9f3212f:
|
size-limit report 📦
|
@@ -55,7 +55,8 @@ export const FocusTrap: React.FC<FocusTrapProps> = ({ | |||
|
|||
const nodes: HTMLElement[] = []; | |||
// eslint-disable-next-line no-restricted-properties | |||
ref.current?.querySelectorAll(FOCUSABLE_ELEMENTS).forEach((focusableEl) => { | |||
const allFocusableNodes = Array.from(ref.current.querySelectorAll(FOCUSABLE_ELEMENTS)); |
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.
У Array.from
примерно тот же уровень поддержки: https://caniuse.com/?search=Array.from
Ни IE, ни Android 4-й версии его не поддерживают
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.
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.
Нет 100% уверенности, что он работает. Может нам просто не репортят о проблемах. На счёт полифилла — я ставлю на то, что babel не полифилит ни from
, ни forEach
. Это можно проверить, собрав библиотеку.
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.
Сейчас я бы использовал Array.prototype.forEach.call(ref.current.querySelectorAll(FOCUSABLE_ELEMENTS), cb)
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.
Почему не пробежаться обычным for of
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.
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.
Ну раз бенчи, то вот https://jsben.ch/2uEkr
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.
Уф давайте без бенчей это прохладный код
👀 Styleguide deployedSee the styleguide for this PR at https://vkcom.github.io/VKUI/pull/2099/ |
ab3395f
to
9f3212f
Compare
А не вариант заполифиллить Например, где-нибудь здесь: https://github.com/VKCOM/VKUI/blob/master/src/lib/polyfills.ts function makeNodeListForEach(collection) {
if (collection && !collection.prototype.forEach) {
if (Array.prototype.forEach) {
collection.prototype.forEach = Array.prototype.forEach;
} else {
collection.prototype.forEach = function(callback, thisArg) {
thisArg = thisArg || window;
for (let i = 0; i < this.length; i++) {
callback.call(thisArg, this[i], i, this);
}
};
}
}
}
makeNodeListForEach(window.NodeList);
makeNodeListForEach(window.HTMLCollection); |
Зачем проверка на Array.prototype.forEach? Упростить можно до if (canUseDOM) {
window.NodeList.prototype.forEach = Array.prototype.forEach;
window.HTMLCollection.prototype.forEach = Array.prototype.forEach;
} |
Напомню про #1724 Глобальные полифиллы не надо больше пожалуйста |
Я согласен с Вовой, что все эти махинации со встроенными конструкторами доведут до беды. Предлагаю юзать дедовские методы вызова методов массива на коллекции дом-элементов. |
Fixes #2098.