Problem/Motivation
https://www.drupal.org/project/drupal/issues/2158943 looks like a herculean task. Therefore, it is necessary to break it down into small sub-tasks that will bring us closer to the final result.
Proposed resolution
Remove jQuery Event from dialog events events. And pass the special `DrupalDialogEvent extends Event` instead.
API changes
Rewrite all core $(window).on({'dialog:... to customEvent listeners to avoid core gitlab CI failures about deprecation messages.
$(window).on('dialog:EVENTTYPE') still BC but their listeners will receive deprecation messages.
$(window).on('dialog:beforecreate') became window.addEventListener('dialog:beforecreate')
Deprecation script checking if old `dialog:beforecreate` presented in $._data(window, 'events');
If presented we trigger deprecation message.
Testing instructions.
1. Review changed dialogs. They should work as before patch.
2. Revert any of changed dialog. Or use some contrib module which uses `dialog:EVENTTYPE` -> you will get deprecation message in console while dialog after/before create/close.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | 3390549-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #56 | 3390549-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-3390549
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
finnsky commentedComment #4
finnsky commentedSeems some cleanup needed in
core/misc/dialog/dialog.position.js
Comment #5
finnsky commentedCurrent Functional Javascript Test failure seems related to core/modules/block/js/block.js:139
https://i.gyazo.com/1176e9dd6dd6554a6652f61ef36721e4.gif
Not to this MR
Issue found: https://www.drupal.org/project/drupal/issues/3384853
Comment #6
finnsky commentedComment #8
smustgrave commentedOnly rebased to get tests to run again,
Comment #9
smustgrave commentedAs we thought was random.
Applied the MR and edited a view, used layout builder, and media library without issue, believe that would cover the js files.
Still needs sign off from the javascript maintainer but from what I see the changes seem fine. Eventually is there any kind of rule or check we could add?
Was told that can mark issues RTBC that are waiting on submaintainer so thats what I'm going to do.
Comment #10
finnsky commentedRebased
Comment #11
anybodyJust ran into this in Homebox 3.x implementation:
Tried to replace
by
BUT that's not possible: https://stackoverflow.com/questions/25256173/can-i-use-jquery-trigger-wi...
So would be super cool to have this fixed or at least also trigger the vanilla JS event.
The attached MR will not solve this, as it still uses jQuery .trigger() and .on()!
So I guess we need to wait for #2158943: Add a native dialog element to deprecate the jQuery UI dialog to solve this? Or can we go further by triggering a native event on window?
Comment #12
finnsky commented@Anybody hi! thank for review.
Yes this is small MR and only cares about event parameter. Not listener or event type.
This is how we can move forward with small steps.
Comment #13
larowlanWhat are the BC implications here? I assume anyone with a listener will have issues with the changes here.
Can we do this in a BC compatible manner?
Perhaps dispatch different events without jQuery and deprecate the old event?
Comment #14
finnsky commented@larowlan
Please take a look at the last commit! This is what you mean?
@Anybody it will also work for your question.
Comment #15
larowlan@finnsky 😍 love it!
Comment #16
smustgrave commentedHate to do it but seems to have caused test failures.
Comment #17
finnsky commentedSeems exact reason of test failures is this deprecation message
Comment #18
larowlanSomething in core listening to the old events?
If so, it works 😁
Comment #19
finnsky commentedAdded condition to check if `dialog:beforecreated` listener presents on page.
Only in this case old event will triggered. And deprecation message will appear.
Comment #20
finnsky commentedComment #21
finnsky commentedComment #22
finnsky commentedComment #23
finnsky commentedIt was 20 minutes Adventure! :)
I had to replace all usages to new listeners because seems core not allows to keep deprecated messages.
Checked all scripts/events manually. All fine Seems autotests also passed.
Please review!
Comment #24
finnsky commentedComment #25
finnsky commentedSome new tests failure gonna fix. Review still needed.
Comment #26
nod_I like this a lot.
One major concern is the renaming of the event, I think we can avoid having to rename it because that would be a pain for contrib to deal with.
I'd like to remove only the
.triggercall, not addevent listeners yet. That will allow people to use dom events without breaking their existing code. Then we can remove jquery.on afterwards.Comment #27
nod_tags
Comment #28
finnsky commentedThank you for review. Gonna rework it according feedbacks.
Comment #29
finnsky commentedRE: #28
We cannot keep Deprecation messages in current core code. Because of pipeline failures.
So that's why i had to rework core `.on()` Seems it is minimal change we can provide in one MR.
Comment #30
finnsky commentedComment #31
anybodyTests are sadly still failing.
Comment #32
finnsky commentedProbably that were random tests failures. Now seems passed on everything. Sending back to review.
Comment #33
anybodyImpressive work @finnsky! Back to RTBC. All feedback seems addressed.
Comment #34
finnsky commentedLet's review again. I forgot to rename one event.
Comment #35
finnsky commentedit was just dialogAfterclose -> dialog:afterclose change. so keep in RTBC. Test still passed.
Comment #37
quietone commentedI'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions.
The issue summary includes a list of API changes. If that is up to date this needs a change record.
Leaving at RTBC.
Comment #38
catchComment #39
finnsky commentedAdded some IS updates to be aligned with current state.
Comment #40
nod_It's solid work, a couple of comments. Mainly about keeping the settings value alterable and using a subclass of Event instead of CustomEvent everywhere.
Setting NW for feedback and the change record.
Comment #41
finnsky commentedComment #42
nod_few things left, the change record needs more details
Comment #43
finnsky commentedThank you! Fixed feedbacks
Comment #44
finnsky commentedComment #45
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #46
finnsky commentedComment #47
larowlanThis looks great, thanks @finnsky for such a thorough solution
Looks like nod_ has been reviewing this along the way, It looks good to me but I'll defer to his expertise.
Removing the Needs Framework Manager tag
Comment #48
bnjmnmSwitching to NW to address the (admittedly superficial-ish) feedback on the MR. I really like how this is approached - I've witnessed several attempts over the past few years to implement something like this and this approach not only solves the problem, but it does it pretty elegantly. The change record covers the necessary info, too, so I'm removing that tag
Comment #49
finnsky commentedResolved feedbacks.
Please rereview :)
Comment #50
finnsky commented@bnjmnm could you please review again? i just rebased
Comment #51
finnsky commented@bnjmnm @nod_
Thank you for reviews!
Seems we are ready to go. I'll request some tests there.
Comment #52
catchLooks like this needs a rebase.
Comment #53
nod_rebased
Comment #54
finnsky commentedIt seems now has random failure in tests.
Comment #55
nod_reran the failing test, green now.
Comment #56
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #57
nod_Comment #58
nod_I was involved with the code so I wanted to have another person RTBC so that I could commit but it doesn't seem to help get that in. It's a 11.x commit only.
Comment #60
pravesh_poonia commentedsorry, comment by mistake
Comment #62
nod_@Pravesh_Poonia I'm not sure what you mean by "But checked MR, changes looking fixed now" . Your text looks automated/generated, could you elaborate as to what you were trying to do? Thanks
Comment #63
catchOne small comment on the MR about the deprecation target - left a suggestion to change it to 10.3.0, but then I saw @nod_ say it's an 11.x commit only, it's not entirely clear to me why we wouldn't backport the deprecation to 10.3 too, generally we've avoided adding deprecations specific to the .0.0 of a new major so that modules don't get new warnings immediately after adding major version compatibility.
I'm not qualified to review the details of the js here, but general +1 on the approach. Just had serious pain with dialog and the jQuery 4 update so any small steps we can take to simplifying it will help.
Comment #64
nod_I was being too cautious limiting to 11.x (was still provisional at the time, might be part of the reason too). I do think it's important to keep the BC layer around for the whole D11 support window
So yeah, should be in 11.x and 10.3.x otherwise it'll be hard to remake a patch that cherry pick cleanly.
Comment #66
bnjmnmThis is great!
Committed to 11.x
Will also commit to 10.3.x, but would first like to run tests on that combo as I've encountered a few JS patches that had unexpected backport surprises
Comment #68
nod_awesome, there was a conflict in libraries.yml on the backport, opened a MR for 10.3.x
Comment #69
finnsky commented10.3.x pipeline passed now
Comment #72
longwaveCommitted and pushed 99af345889 to 10.4.x and 66faba3a71 to 10.3.x. Thanks!
Comment #73
nod_Thanks! Published the change notice, does it need release note?
Comment #74
longwaveDeprecation is triggered automatically and we have a change record, there's nothing here that we need to notify site owners about in the release note that I can see.
Comment #77
agentrickardThis is throwing fatal JS errors and breaking contrib modals:
[EDIT] This may be due to browser cache on multiple dev site rebuilds. I will file a real ticket if the issue persists.
Comment #78
karlsheaIt's also broken Bootstrap Modal, looking for
event.dialogwhere instead the fix is to look for$event.dialog.Comment #79
ahmad khader commentednvm
Comment #80
ahmad khader commentedComment #81
ahmad khader commented