-
Notifications
You must be signed in to change notification settings - Fork 215
refactor(chrome-ext): drop jquery dependency #2052
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
Conversation
Drafting this for now, realized |
I believe the changes should be now ready to review. Currently writing this message with the Firefox extension enabled and it is working just fine. I also verified with a debugger that the query selectors trigger appropriately. |
if (this.getAttribute('data-enable-grammarly') == 'false' || this.disabled || this.readOnly) { | ||
document.querySelectorAll<HTMLTextAreaElement>('textarea').forEach((element) => { | ||
if ( | ||
!isVisible(element) || |
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.
This might still be incorrect.
<textarea>
that is below the fold on a static page will be skipped over if it will not appear in the viewport within the first second.
A more compatible replacement could be https://youmightnotneedjquery.com/#is_visible
For the most part, this looks good to me. The visibility check might be technically different, but I think it's close enough that it won't cause a problem. For posterity, could you fully explain your reasoning for removing JQuery? |
Easy way to see it for yourself is if you have a plain html file with enough The replacement I linked turns out to be lifted from actual jQuery source, so one should not be discouraged from using it if the current isVisible check turns out to be problematic in practical use. Having two different isVisible checks in a single file however may get confusing, but that's a different problem.
To me it feels just the wrong tool for the job in this particular instance. It's a pretty big library (~30% of shipped JS) for doing 4 selectors that gets loaded on every page load. The problem isn't that it is necessarily jQuery, it's just that it's massively underutilized. Using it more however does not make it a better tool as modern web has alternatives in vanilla JS to most of the common jQuery patterns. My main concern is how this ties to how it's used in the extension. As it is part of content script, then my understanding is that every time a new tab is opened or a page is loaded, this will incur loading another instance of jQuery into memory. As it is right now, this overhead can be easily avoided, leading to a better browsing experience - either pages loading/becoming responsive faster, making battery last longer or being able to keep open more tabs at a time. I do admit, the gains from this may turn out to be insignificant, but they are gains nonetheless. |
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 absolutely agree with all of your points. I think this PR is in a good enough state to be merged. I'll monitor for any issues before running a release.
Thanks for helping out! |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [Automattic/harper/harper-ls](https://github.com/Automattic/harper) | minor | `v0.65.0` -> `v0.67.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>Automattic/harper (Automattic/harper/harper-ls)</summary> ### [`v0.67.0`](https://github.com/Automattic/harper/releases/tag/v0.67.0) [Compare Source](Automattic/harper@v0.66.0...v0.67.0) #### What's Changed - feat(core): Add support for Python docstrings by [@​rushter](https://github.com/rushter) in [#​2038](Automattic/harper#2038) - feat(web): revise landing page by [@​elijah-potter](https://github.com/elijah-potter) in [#​2046](Automattic/harper#2046) - fix(web): remove faq link by [@​mcecode](https://github.com/mcecode) in [#​2047](Automattic/harper#2047) - fix(obsidian): properly manage dictionary by [@​elijah-potter](https://github.com/elijah-potter) in [#​2050](Automattic/harper#2050) - fix(web): will now work on Hacker News by [@​elijah-potter](https://github.com/elijah-potter) in [#​2053](Automattic/harper#2053) - docs: remove or update remaining faq page links by [@​mcecode](https://github.com/mcecode) in [#​2061](Automattic/harper#2061) - build(deps): bump ordered-float from 5.0.0 to 5.1.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2059](Automattic/harper#2059) - refactor(chrome-ext): drop jquery dependency by [@​Ingramz](https://github.com/Ingramz) in [#​2052](Automattic/harper#2052) - fix(wasm): remove overlaps in the proper order by [@​elijah-potter](https://github.com/elijah-potter) in [#​2062](Automattic/harper#2062) - fix(chrome-plugin): errors saving rule state in Firefox by [@​elijah-potter](https://github.com/elijah-potter) in [#​2064](Automattic/harper#2064) - fix(chrome-ext): disable on comboboxes by [@​elijah-potter](https://github.com/elijah-potter) in [#​2063](Automattic/harper#2063) - More irregular verbs for 'have went' linter by [@​hippietrail](https://github.com/hippietrail) in [#​1973](Automattic/harper#1973) #### New Contributors - [@​rushter](https://github.com/rushter) made their first contribution in [#​2038](Automattic/harper#2038) - [@​Ingramz](https://github.com/Ingramz) made their first contribution in [#​2052](Automattic/harper#2052) **Full Changelog**: <Automattic/harper@v0.66.0...v0.67.0> ### [`v0.66.0`](https://github.com/Automattic/harper/releases/tag/v0.66.0) [Compare Source](Automattic/harper@v0.65.0...v0.66.0) #### What's Changed - fix: format of checkboxes was broken in feature request template by [@​hippietrail](https://github.com/hippietrail) in [#​1992](Automattic/harper#1992) - fix: org-mode add list item parsing with tab normalization by [@​eloycoto](https://github.com/eloycoto) in [#​1989](Automattic/harper#1989) - feat(chrome-ext): use new CSS Highlights API where possible by [@​elijah-potter](https://github.com/elijah-potter) in [#​1970](Automattic/harper#1970) - feat: add ink support by [@​FreddieGilbraith](https://github.com/FreddieGilbraith) in [#​1894](Automattic/harper#1894) - feat:besides the point→beside the point, don't can→can't by [@​hippietrail](https://github.com/hippietrail) in [#​2021](Automattic/harper#2021) - Add more phrasal verb exceptions by [@​hippietrail](https://github.com/hippietrail) in [#​2002](Automattic/harper#2002) - feat(core): create initial `MissingTo` rule by [@​elijah-potter](https://github.com/elijah-potter) in [#​1990](Automattic/harper#1990) - fix(core): address problems with prepositional phrases by [@​elijah-potter](https://github.com/elijah-potter) in [#​2022](Automattic/harper#2022) - build(deps): bump tree-sitter from 0.25.9 to 0.25.10 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2029](Automattic/harper#2029) - Criteria phenomena by [@​TomasoAlbinoni](https://github.com/TomasoAlbinoni) in [#​2028](Automattic/harper#2028) - build(deps): bump serde from 1.0.226 to 1.0.228 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2032](Automattic/harper#2032) - build(deps): bump thiserror from 2.0.16 to 2.0.17 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2030](Automattic/harper#2030) - chore: missing words, annotations by [@​hippietrail](https://github.com/hippietrail) in [#​1999](Automattic/harper#1999) - feat(core): create tagged linting function by [@​elijah-potter](https://github.com/elijah-potter) in [#​1998](Automattic/harper#1998) - build(deps): bump indexmap from 2.11.1 to 2.11.4 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​2031](Automattic/harper#2031) - fix: nominal wants issue [#​2010](Automattic/harper#2010) by [@​hippietrail](https://github.com/hippietrail) in [#​2034](Automattic/harper#2034) - fix(ci): reduce redundancy in CI by [@​elijah-potter](https://github.com/elijah-potter) in [#​2037](Automattic/harper#2037) - feat(core): use a better quote-pairing algorithm by [@​elijah-potter](https://github.com/elijah-potter) in [#​2036](Automattic/harper#2036) #### New Contributors - [@​FreddieGilbraith](https://github.com/FreddieGilbraith) made their first contribution in [#​1894](Automattic/harper#1894) - [@​TomasoAlbinoni](https://github.com/TomasoAlbinoni) made their first contribution in [#​2028](Automattic/harper#2028) **Full Changelog**: <Automattic/harper@v0.65.0...v0.66.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzIuNSIsInVwZGF0ZWRJblZlciI6IjQxLjEzNS41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Issues
N/A
Description
This pull request removes jQuery from the browser extension content script in favor of native
document.querySelectorAll
.Demo
N/A
How Has This Been Tested?
Working from a Windows environment, I was unable to build the browser extension successfully.
Manually tested the Firefox extension built by the CI in this pull request and the selectors appear to be all selecting just fine.
Checklist