-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Workaround for Chrome 140 issues #4600
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
Workaround for Chrome 140 issues #4600
Conversation
WalkthroughThe $.fn.sortSelect plugin in src/js/utils/common.js has been effectively disabled by commenting out its internal logic due to Chrome v140 issues. The function remains defined and returns this, but no option collection, sorting, or DOM updates occur. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (1 passed, 2 inconclusive)❌ Failed checks (2 inconclusive)
✅ Passed checks (1 passed)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
Preview URL: https://0f984895.betaflight-configurator.pages.dev |
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/js/utils/common.js (1)
95-133: Disabling sortSelect is a functional regression; guard and keep behavior instead.Commenting out the body turns the plugin into a no-op and will leave selects unsorted across the UI. Drawing on the retrieved learnings (prior native DOM rewrite), keep the logic but wrap it in a try/catch so only broken environments degrade gracefully.
Apply this diff:
$.fn.sortSelect = function (text = "") { - /* - - Chrome v140 does not work with sortSelect function properly. - Disabling it for now until a fix is found. - - this.each(function () { - const select = this; - // Collect option data - const optionData = Array.from(select.options).map(opt => ({ - value: opt.value, - text: opt.text, - selected: opt.selected, - disabled: opt.disabled, - })); - - // Sort option data - optionData.sort((a, b) => { - if (a.text === text) { return -1; } - if (b.text === text) { return 1; } - return a.text.localeCompare(b.text, window.navigator.language, { ignorePunctuation: true }); - }); - - // Remove all options - while (select.options.length) { select.remove(0); } - - // Add sorted options - optionData.forEach(opt => { - const option = document.createElement("option"); - option.value = opt.value; - option.text = opt.text; - option.selected = opt.selected; - option.disabled = opt.disabled; - select.add(option); - }); - }); - - */ + // Chrome 140 workaround: keep behavior but guard with try/catch so only failures degrade to no-op. + try { + this.each(function () { + const select = this; + if (!select || select.tagName !== "SELECT") return; + // Collect option data + const optionData = Array.from(select.options).map(opt => ({ + value: opt.value, + text: opt.text, + selected: opt.selected, + disabled: opt.disabled, + })); + // Sort option data + optionData.sort((a, b) => { + if (a.text === text) { return -1; } + if (b.text === text) { return 1; } + return a.text.localeCompare(b.text, window.navigator.language, { ignorePunctuation: true }); + }); + // Remove all options + while (select.options.length) { select.remove(0); } + // Add sorted options + optionData.forEach(opt => { + const option = document.createElement("option"); + option.value = opt.value; + option.text = opt.text; + option.selected = opt.selected; + option.disabled = opt.disabled; + select.add(option); + }); + }); + } catch (e) { + // Known Chrome 140 issue — fail soft: leave the select as-is. + console.warn("sortSelect: falling back to no-op due to browser bug:", e); + } return this; };
🧹 Nitpick comments (2)
src/js/utils/common.js (2)
117-128: Reduce reflows; using a DocumentFragment may also dodge the Chrome 140 bug.Batch DOM writes via a fragment and replaceChildren; it’s faster and can avoid re-entrant mutation pitfalls.
- // Remove all options - while (select.options.length) { select.remove(0); } - - // Add sorted options - optionData.forEach(opt => { - const option = document.createElement("option"); - option.value = opt.value; - option.text = opt.text; - option.selected = opt.selected; - option.disabled = opt.disabled; - select.add(option); - }); + // Rebuild options with minimal reflow + const frag = document.createDocumentFragment(); + optionData.forEach(opt => { + const option = document.createElement("option"); + option.value = opt.value; + option.text = opt.text; + option.selected = opt.selected; + option.disabled = opt.disabled; + frag.appendChild(option); + }); + select.replaceChildren(frag);
95-99: ScopesortSelectdisabling to Chrome v140 only.$.fn.sortSelect = function (text = "") { + const ua = (typeof navigator !== "undefined" && navigator.userAgent) || ""; + if (/Chrome\/140\./.test(ua) && !/Edg\//.test(ua)) return this; // existing implementation…
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/js/utils/common.js(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: haslinghuis
PR: betaflight/betaflight-configurator#4597
File: src/js/utils/common.js:95-127
Timestamp: 2025-09-09T20:02:33.475Z
Learning: In the Betaflight Configurator codebase, the Chromium v140 compatibility issue with sortSelect was resolved by rewriting the implementation to use native DOM APIs (Array.from, select.options, select.remove, select.add) instead of jQuery DOM manipulation methods (this.children, this.empty().append). The fix still performs DOM operations but avoids the specific jQuery methods that were causing issues in Chromium v140.
📚 Learning: 2025-09-09T20:02:33.475Z
Learnt from: haslinghuis
PR: betaflight/betaflight-configurator#4597
File: src/js/utils/common.js:95-127
Timestamp: 2025-09-09T20:02:33.475Z
Learning: In the Betaflight Configurator codebase, the Chromium v140 compatibility issue with sortSelect was resolved by rewriting the implementation to use native DOM APIs (Array.from, select.options, select.remove, select.add) instead of jQuery DOM manipulation methods (this.children, this.empty().append). The fix still performs DOM operations but avoids the specific jQuery methods that were causing issues in Chromium v140.
Applied to files:
src/js/utils/common.js



Summary by CodeRabbit