Problem/Motivation
We are in the process of deprecating jQuery UI in core. The jQueryUI position library is among the components that need to be removed/replaced.
As mentioned in the parent issue: #3067261: [Plan] Remove jQuery UI components used by Drupal core and replace with a set of supported solutions
The OpenJS Foundation lists jQuery UI as an Emeritus project in https://openjsf.org/projects/ which is described as:
Emeritus projects are those which the maintainers feel have reached or are nearing end-of-life
Proposed resolution
In core, jQuery UI Position is primarily used by other jQuery UI libraries that will be deprecated. There is one instance where it is used in isolation and must be specifically addressed: the Quick Edit module. This means this issue is essentially finding a new library for Quick Edit's positioning.
After evaluating and prototyping the available options, PopperJS was the clear winner. It is well supported, widely used, well documented, and offers the necessary features.
Remaining Taks
Choose between https://github.com/HubSpot/tether (probably a bad option, Hubspot was impressibly candid about no longer maintaining this) and https://github.com/FezVrasta/popper.js (recommended by Hubspot as a well maintained alternative)Done!Rule out libraries that shouldn't be used due to abandonment, performance, etc.Done!Create a prototype for the remaining libraries to be used in place of jQuery UI for Quick Edit's positioningDone!If prototype appears to function well, get sign-off from Quick Edit maintainer.Done!- Validate the prototype with the JavaScript maintainers
- Get the patch through the core gates
User interface changes
Ideally, there will be none. Any changes shouldn't be more than a mildly noticeable pixel difference
API changes
Adds a new third-party dependency, popper.js.
Dependency evaluation of popper.js
- Maintainership of the package: The package is actively maintained with numerous contributors, and the maintainer is responsive and even followed up here on d.o. Thanks @FezVrasta!
- Security policies of the package: The package does not have an explicit security policy documented on GitHub or in the codebase, but the maintainer has indicated they're comfortable following coordinated disclosure with us: https://github.com/FezVrasta/popper.js/issues/823 Both the current and the previous major version receive security coverage.
- Expected release and support cycles: The release schedule is irregular based on the maintainer's availability, but there are releases every few months. https://github.com/FezVrasta/popper.js/releases The maintainer follows semver strictly insofar as one can with a JavaScript library.
- Code quality: ES6, >1800 dependents, used by major projects (e.g Bootstrap, Material UI), available on 5 package managers, multiple distribution targets, and provides guidance on how to use with all the popular JS libs (React, Vue.js, Angular, AngularJS, Ember.js and more) as well as readily available packages for those too.
- Other dependencies it would add, if any: no dependencies, only dev dependencies that Drupal never pulls in.
Data model changes
N/A
Release notes snippet
The Quick Edit module previously depended on the jQuery UI Position asset library. Since jQuery UI is end-of-life, we've removed the dependency on jQuery UI position and added a dependency on the Popper.js library instead. It's recommended that any modules or themes that use jQuery UI position also update their code to use Popper.js. Any module extending QuickEdit may also require small changes. Read the Popper.js added to Drupal core to replace jQuery UI Position for more information.
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | 3074267-37.patch | 154.57 KB | bnjmnm |
| #37 | interdiff_29-37.txt | 390.27 KB | bnjmnm |
| #29 | interdiff-22-29.txt | 3.27 KB | zrpnr |
| #29 | 3074267-29.patch | 543.9 KB | zrpnr |
| #29 | popper-modifiers.png | 127.46 KB | zrpnr |
Comments
Comment #2
wim leersThis both made me smile and made me thankful. Yay for responsible open source maintenance!
IIRC
.position()is also responsible for the movement animation. I think a difference in behavior there is absolutely acceptable, especially considering #2090945: Polish entity toolbar's positioning.In other words: I think there is more leeway here. But you're right that while the page is static (no scrolling, no clicking of the user on other in-place editable fields), the visual difference should be minimal.
👋🏻 I'm here!
Comment #3
bnjmnmHere's a prototype of Quickedit using popperjs instead of jQueryUI position().
Popper looks mature, versatile, used by several large enterprises, and a little bit confusing at first due to it's capabilities and not-immediately-inviting documentation -- in other words it's a good fit for Drupal.
Comment #4
wim leers😅
https://popper.js.org/ is a nice find! gzip size is 7.25 KB — don't let the patch size fool you.
Manually tested. It loads, runs without JS errors, but … it doesn't quite work correctly yet, it doesn't follow around properly:

(That toolbar is supposed to be positioned just above the title field.)
Still, it looks very promising! I It was just a prototype after all :)
Comment #5
finnsky commentedcatched some mirracle disappear

Comment #6
finnsky commentedFixed described in #4 and #5
+1 for popper
Comment #7
wim leersThat is a huge step forward, @finnsky, thanks, and well done! 🥳
There are two problems I am still observing:
While scrolling, Popper seems to be recalculating for every scroll event, causing the toolbar to remain in the exact same place
if there is no room in the viewport for the toolbar to fit above the currently focused field, the toolbar is first positioned in the bottom right of the viewport and then animates to the appropriate place, instead of just moving to the appropriate place right away, without the jump to the bottom right
The attached screencast demonstrates this. It also demonstrates how the more typical initial appearing of the toolbar now does work! 👍
Comment #8
finnsky commentedComment #9
finnsky commentedPopper has own scroll/resize event listeners
https://popper.js.org/popper-documentation.html#Popper.Defaults.eventsEn...
And we have own enabled
https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/quicke...
So at least one of them should be disabled. Gonna digg it a bit more
Comment #10
finnsky commentedSeems we don't need to update Popper itself since we have own complicated logic.
Comment #11
finnsky commentedAlso added Popper to globals list to pass `lint:core-js-passing` eslint test. Not sure it is valid way. Please check
Comment #12
wim leersPatch doesn't apply! Quick reroll? :)
Comment #13
finnsky commentedsorry, fixed
Comment #14
finnsky commentedComment #16
wim leersIt'll need some JS test updates because it failed tests … but … THIS WORKED PERFECTLY! 😲👏👏👏👏
Once this passes tests, I will RTBC this. Awesome work @finnsky!
Comment #17
droplet commentedI believe this part of code doesn't work when the editor toolbar hit the Toolbar modules' bar.
And it's probably overridden by the Poper below? And
refinePopperhasn't never called?And Poper used CSS transform :)
There's no simple way to handle the above case I think. To execute the above function after Popper.update?
Comment #18
finnsky commentedactually it was easier to me to rewrite everything:)
#17
More than that: We recreate popper instead of reposition on every positionToolbar() call
Gonna fix found issues.
Comment #19
finnsky commented2 options for make tests passed:
1) Set
in Popper settings.
2) Set
in core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php
to skip css transforms disabling.
Comment #20
wim leersThat seems reasonable. (Nice research by the way, that sure sounds tricky!)
Comment #21
finnsky commenteda little bit closer to target. tests should be passed with #19 first option.
1) removed recreation of popper instance. added it in `this` instead.
2) Removed initial force styles
3) Enabled back `refinePopper` onCreate and onUpdate.
Comment #22
wim leersPatch review
👎 Missing correct version, missing license information, should use minified popperjs.Done. ✅🤓 Nit: missing blank line.Done. ✅👍This code is simply not necessary anymore due to how Popper works versus how jQuery UI's
.position()works. Removed. ✅🥳
Overall review
👎✅ This should use thepopper.min.js(21 KB ungzipped), notpopper.js(88 KB ungzipped).core/jquery.ui.position'sposition-min.jsis 6 KB ungzipped (but minified), but depends oncore/jquery.uiwhich is another 8 KB ungzipped (but minified) which itself depends oncore/jquerywhich is another 88 KB ungzipped (but minified). There is not a huge difference in download size, this is one step on the way to not use jQuery everywhere, and the only place it is used in Drupal core (Quick Edit) is very JS-heavy anyway.All thumbs up, so …
RTBC! 🥳— RTBC once we get a positive response at https://github.com/FezVrasta/popper.js/issues/823 :)Comment #23
wim leersI think the response from the Popper.js maintainer at https://github.com/FezVrasta/popper.js/issues/823#issuecomment-525350214 addressed our concerns! 🥳
Comment #24
FezVrasta commentedI quickly looked at the diff, note that `preventOverflow` and `flip` are two Popper.js modifiers, so they should all live into the `modifiers` object.
Comment #25
droplet commentedI compared the old and new implementation. I can't tell which is correct. There're working differently.
I don't understand the code comments in the refinePopper. I think only the above code is still used. Other parts of code can be removed from the new implementation?
_.defer for onCreate/onUpdate is required if we take performance seriously
If no BC, this is able to style with x-placement, no more extra class. x-placement is also the Poper.js way to style things. I always preferred not to create our own thing. Otherwise, other lib supporting Poper.js can't connect with Drupal without modification :P
I think this is worth to drop a TODO and come back to fix the tests when we have time. A better and simple deal, I'd export it to drupalSetting and override it on tests only. I didn't investigate the code deeply, probably this is already able to get the instance from Backbone or something.
Comment #26
zrpnrWhen this issue is completed, the only dependencies on jQuery UI Position will be other jQuery UI libraries!
Created #3078116: Deprecate jquery.ui.position to return to once those other issues are completed.
Comment #27
lauriiiIt seems like the quickedit toolbar movement is stuttering a bit. Is this even something we could solve? This doesn't necessarily have to block a commit but in that case, it would be good to open a follow-up to research that.
Edit: maybe it's not stuttering. It could be just that while transitioning, the toolbar moves too low and because the toolbar needs to move back, it makes it look like it's stuttering.
Maybe we could just rename this to js-popper-processed. No need for BEM style modifiers on js- prefixed classes.
Comment #28
wim leers#27: weird, that's not the behavior I observed. Maybe due to viewport dimension differences. If #24 fixes it, great, once a new patch is uploaded I'll manually test again.
Comment #29
zrpnrWelcome @FezVrasta! Thank you for that suggestion, I made the change and it fixed the issues I was seeing with toolbar placement and flip.
More specifically, the jQuery UI suggested.top value and the Popper data.offsets.popper.top value in the refine method are now the same.
#27.2 The toolbar seemed a little jumpy to me too, and it would sometimes shoot across the screen a bit erratically. I think it was due to the modifiers as well.
#27.3 Changed to js-popper-processed.
Comment #30
wim leersI suspect
gpuAcceleration: falseis the reason for the occasional stuttering.@finnsky did this in #19 to make tests pass.
I changed it locally to
true, but it still stutters from time to time.It looks like other people have run into this too: https://github.com/FezVrasta/popper.js/issues/699 and especially https://github.com/FezVrasta/popper.js/issues/720. The latter is actively being worked on by @FezVrasta.
Honestly, this slight stutter is not the end of the world. I do not think it should block us from migrating away from https://jqueryui.com/position/. Even more so because the current positioning itself is imperfect already — see #2090945: Polish entity toolbar's positioning.
Comment #31
bnjmnmComment #32
bnjmnmUpdated IS again because
<del>is exotic to me.Comment #33
lauriiiThe patch is > 500kb because it's adding both, a non-minified version and a minified version of the library. Should we remove the non-minified version of the library from the patch?
Comment #34
wim leers#33: does that really matter? Including the unminified version is handy to be able to swap out during debugging. We also do this for Backbone, jQuery, jQuery Once. We don't do it for the other JS libs in
core/assets/vendorapparently.Comment #35
lauriii#34 If we store unnecessary code in core, it leads into more data transferred when sites are being updated which as a result increases our carbon print. Maybe this doesn't feel all that significant but in large scale, even small things have some impact. As far as I can see, there are 11 .js files being added as part of the library which only one is being used. If we can avoid 400kb from being added to core, it could help us save over 110gb of data being transferred as part of each Drupal release.
I do agree that we should keep the DX in mind, and therefore we should keep the .map files which would enable debugging with less data being added to core.
Comment #36
wim leers❤️🌱🌍 You've convinced me!
Comment #37
bnjmnmRemoved the superfluous files and also moved where popperjs appears in core.libraries.xml so it's consistent with the comment at the top of the file
Comment #38
xjmSince this is adding a new JS dependency to core, we should have explicit framework, release, and JS maintainer signoff. Adding the dependency information and evaluation to the IS under the API changes section. I answered the first few points but left the code quality signoff to the framework managers and need evaluation of the package's own dependencies: https://github.com/FezVrasta/popper.js/blob/master/package.json
The IS is confusing; did we change the proposed resolution? I'd say just make the proposed resolution say "Use popper.js" and then put the struck-through bullets under remaining tasks. :)
Comment #39
xjmComment #40
wim leersPopper.js has no dependencies. https://github.com/FezVrasta/popper.js says that too:
It only has dev dependencies, which do not affect us (Drupal): https://github.com/FezVrasta/popper.js/blob/master/package.json#L6.
Workspaces is a
yarnthing: https://yarnpkg.com/lang/en/docs/workspaces/, https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/. It's not a dependency.ES6 = ES2015. And the Popper.js project page says:
It has 95% test coverage, has hundreds op hundreds upon dependents. I think that means it meets the bar.
Comment #41
wim leersNote: IMHO we could mark the
core/jquery.ui.positionasset library as deprecated in this issue, but we already have #3078116: Deprecate jquery.ui.position for that as a follow-up. Doing it separately also works for me — the only thing that matters is that it actually happens :)Comment #42
lauriiiComment #43
lauriiiI still think we should mark
core/jquery.ui.positionas deprecated in a follow-up since we will still have other jQuery UI libraries using it after this change, and therefore we don't know when we would be able to actually remove it.The package.json previously linked in this issue is a monorepo file that doesn't affect us. However, looking at the actual package.json in https://github.com/FezVrasta/popper.js/blob/master/packages/popper/packa..., it seems that there also isn't any actual runtime dependencies.
The library itself looks impressive. The code and APIs are well documented. As mentioned by @Wim Leers in #40, it also has tests running on multiple browsers.
It seems like most desktop browsers supported by Drupal are automatically covered by their automated tests. It seems like Opera is the only desktop browser missing from if we use the list that we've been discussing in: #2390621: [policy, no patch] Update Drupal's browser support policy. We should also manually ensure that the behavior remains functional on supported mobile browsers since the library isn't tested automatically on any mobile browsers.
Comment #44
catchThe combination of xjm and Wim Leers' work here means I think we can remove the needs release manager review tag.
Agreed on not marking jQuery UI Position deprecated until we've deprecated the other libraries that it depends on.
Comment #45
bnjmnmIssue created for deprecating jquery.ui.position once the libraries requiring it are deprecated #3081532: deprecate jquery.ui.position
Comment #46
wim leersGood catch, makes sense!
Fortunately modern Opera is Chromium-based, so if works on Chrome it reasonably should also work on Opera, unless in obscure areas. This is far from obscure, so should behave identical.
Comment #47
bnjmnmI performed additional manual tests on browsers not included in the tests mentioned in #43 Consisted of working with quickedit on a node with several fields where I scrolled and switched fields often in an attempt to trip up PopperJS. In each instance there was no noticeable difference between it and jQueryUI position.
Desktop: Opera
iOS: Safari (as far as I know emulators do not provide the ability to install other browsers?)
Android: Chrome, Firefox, Opera
Comment #48
wim leersExcellent! I think most of the issue summary update improvements that @xjm asked for in #38 have happened, but we should mention we did manual tests in browsers and link to the relevant comments. Once the issue summary update happened.
Frontend framework manager review happened (by @lauriii in #43), I don't think this needs non-frontend framework manager review on top of that.
The only real remaining task here is JavaScript maintainer review.
Comment #49
justafishThere's some "that" usage it would be nice to get rid of it, but looks like that came from the current implementation so it's fine with me for it to not be in scope for this change.
I tested this with quick edit in Umami and it works well 👍
Comment #50
lauriiiThanks for the review @justafish! Confirmed in DM that we can remove the "needs JavaScript review" tag now. 👏
Comment #51
larowlanI think a missing element here is follow up task to add a PR against https://github.com/FezVrasta/popper.js/blob/master/MENTIONS.md to propose adding Drupal to the list.
Great work all.
Comment #52
wim leersWe still need that issue summary update, and a the follow-up that @larowlan mentioned also sounds sensible :)
Comment #53
lauriiiIssue summary update was requested in #38. AFAIK all of the points that were asked to be updated, has received an update between now and then.
Comment #54
xjm💃🏻
Comment #55
zrpnrAdded #3085051: Follow-up to #3074267 to propose adding Drupal to popper.js mentions for @larowlan suggestion in #51
Comment #56
bojanz commentedGreat work, everyone!
It might also make sense to adopt tooltip.js (which is based on popper.js) as a replacement for jquery.ui.tooltip. I'll raise this in #2207383: Create a tooltip component.
Comment #57
catchWe're missing a change record here. It should have instructions for contrib/custom code that is directly using the jQuery library (even if it's just a pointer to the changes that were made for quickedit).
Also a release notes snippet.
Comment #58
zrpnrAdded a draft change record
I updated the IS as well to add a short release notes snippet.
Comment #59
wim leersThanks, @zrpnr! Fixed some nits, but looks 👍
Comment #60
johnwebdev commentedIt would be really nice to have a "See instructions for contrib/custom code" link in the change record, I recall someone had written something about that somewhere, but can't seem to locate it. :p
Comment #61
droplet commentedThe remarkable part is the `boundariesElement` element, which is a custom element to avoid the toolbar issue. (Now come up an idea to rename it to reflect the usage)
Other than that, the official docs should tell more details.
This patch is not a good example I think. This is a complicated case and as my code review above, few parts of the code are unnecessary.
Comment #63
xjmComment #65
catchTest fails are unrelated, back to needs review.
Comment #66
wim leersIt actually was at RTBC, so restoring to that status.
Comment #67
xjmExpanding the release note.
Comment #68
xjmAlright, @catch and I agreed this is probably a safe change to make in 8.8. It's purely API addition plus internal change to QuickEdit; we aren't even deprecating the jQuery UI library since position is also required internally by dialog and such. And it's highly unlikely that anyone is going to be fiddling with QuickEdit's internal JS.
Thanks everyone! Removing the RM doorstop tag.
Comment #69
wim leersLet's just say I am both deeply impressed by and feel very sorry for whomever is doing that.
Comment #70
xjmSaving issue credits. I also did some more work on the change record: https://www.drupal.org/node/3086643/revisions/view/11595411/11608123
Comment #74
xjmCommitted to 9.0.x, 8.9.x, and 8.8.x, and published the change record. Thanks! Two down, thirty-eight to go...
Comment #75
xjmComment #81
larowlanPopper v2 was released - should we try and update to that before D9 ships?
#3108402: Update to Popper.js to 2.0.0