Problem/Motivation
Drupal.js mixes responsibilities: it provides the API, it initializes it and it contains the behaviors attachment/dettachment.
Let's split those for having clearer dependencies and providing a way to contrib for switching out dependencies on domready, mess with how things are initialized.
Proposed resolution
- drupal.init.js performs initialization of the Drupal JS API when dom is ready and adds the js class needed for styling.
- drupal.js contains the Drupal API.
Remaining tasks
Reviews + Manual testing
User interface changes
None.
API changes
Split JS, compatibility break with existing code only if sites had already mangled with Drupal core JS (potentially noone).
Beta phase evaluation
Disruption | Non disruptive, splitted JS files, but if you depended on the library nothing breaks. We can consider this an internal refactoring. |
---|
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Manually test the patch | Novice | Instructions | Yes - see #34 |
Comment | File | Size | Author |
---|---|---|---|
#38 | split_drupal_js-2422017-38.patch | 2.22 KB | penyaskito |
#38 | interdiff.txt | 416 bytes | penyaskito |
#33 | 2422017-8.3.x-reroll-comment-9963045.patch | 2.22 KB | MobliMic |
#26 | core-js-lib-diet-1945262-26.patch | 2.19 KB | penyaskito |
Comments
Comment #1
penyaskitoWe need to add the dependency in several other places, but I want to get feedback on the direction.
Everything works now as long as the contextual module is active.
Comment #2
Wim LeersI have doubts about this.
Anything using Drupal.t() would have to declare a dependency. This would be very useful for locale module actually, to know which files contain translations.
Let's see what nod_ thinks.
Comment #3
Gábor HojtsyIt would need to be Strings.t(), etc. then no? I know JS does not limit us to keep all Drupal.* in one library, but for consistency we are supposed to no?
Comment #4
penyaskitoIf that's the case, as a big disruption this should be postponed to D9. I think it would be useful still to split, let's see what nod_ thinks.
Comment #5
nod_I'm behind the split. How things are split can be discussed a tiny bit more.
For the naming: we can't use
Strings.XXX
that's much too close to the JSstring
object, that would be confusing on top of adding a new global that would confuse the hell out of non drupal people. As for naming it's pretty much free for all. We havemobile.install.js
next tonav-tabs.js
and there is no official relations between how the file is named and what's in there.Moving string functions is good, but we still have api related functions next to behaviors stuff: url, theme, encode path, those manipulate strings as well. What could be a good split is to move initialization-related code and function in their own file like a
drupal.init.js
and leave the rest in drupal.js and add a dependency ondrupal.init
. We don't have to mess all the other libs that way. As for splitting translation related function (and not just string related) that could be good as wim points out.At the very least, this needs work because we use 2 space indent, not 4.
Comment #6
nod_Comment #7
penyaskitoLet's see what do you think about this:
I splitted drupal.js into drupal.init.js, drupal.domready.js and drupal.js:
Tested different scenarios manually and looks like I didn't break anything. I was forced to use weights, because the domready lib and drupal.js have that, but once they are removed the dependencies should resolve correctly.
Comment #8
Gábor HojtsyNot sure this has something to do with D8MI at this point?
Comment #9
Wim LeersThanks! Since that looks to be in accordance with the directives from our JS maintainer in #5: looking great :)
Still using 4-space indentation everywhere though.
Comment #10
penyaskitoShame on me, fixed my IDE settings so it does not happen again.
Comment #11
penyaskitoAdded beta evaluation and fixed proposed resolution with new scope. We will (or not) split the string/translation functions on separate issue.
Comment #12
Fabianx CreditAttribution: Fabianx commentedI think this should get a new @file header?
Comment #13
Jeff Burnz CreditAttribution: Jeff Burnz commentedCan we have a change notice please.
Comment #14
penyaskito@nod_ wanted to have some time to think about this one. Further work should wait for a decision.
(here is when I try to assign it to nod_ but I don't have enough permissions)
Comment #15
Fabianx CreditAttribution: Fabianx commented.
Comment #16
penyaskito@nod_, could you share your concerns about this patch so we can try to move further?
Comment #17
nod_All right had some time to think about it.
I'm not comfortable with the proposed split because we're splitting things that are related with things that are not. Maybe it's because of the naming of the files that it's a little confusing.
Here is my though process: drupal.js contains the Drupal API (not just "the rest" :p) and this API needs to be initialized, hence it depends on a drupal.init.js file that comes after drupal.js. We don't have to add more libraries, we can just say that the
core/drupal
lib is actually 2 js files. That way contrib can switch out dependencies on domready, mess with how things are initialized and we don't have to rename a huge amount of things.window.Drupal = {behaviors: {}};
in drupal.js (can be inside the closure, no need to separate it).Just one little comment:
don't need domready here anymore.
Comment #18
nod_Comment #19
nod_Things should be clear in #17
Comment #20
penyaskitoStarted from scratch looking for the indications at #17.
Manually tested frontpage, quickedit, views and tours. No problems introduced.
I didn't change header files, will appreciate suggestions if we need to.
Comment #21
penyaskito@nod_'s feedback on IRC:
Comment #22
penyaskitoFixed feedback from #21.
I found that the js class was being added twice. An anonymous closure fixed the issue.
Comment #24
YesCT CreditAttribution: YesCT commentedper request from @penyaskito, canceled #20 since head had been failing, so the test was postponed, and there is a new one on this issue anyway.
Comment #25
penyaskitoUpdated issue summary after new point of view.
Added novice contributor tasks for "Needs manual testing"
Comment #26
penyaskitoPer @nod_ on IRC: #22 was wrong, the other js was added by modernizr and its fine.
So new patch, this should be good to go.
Comment #27
nod_I apologize about the "diet" patch name, it was a poor attempt at wit. https://the-pastry-box-project.net/marc-drummond/2015-december-21
Comment #28
droplet CreditAttribution: droplet commentedIt's over-optimizing. We can introduce a global var to on/off the domready init.
Comment #29
droplet CreditAttribution: droplet commentedwhatever, can't do it 8.0.x :)
Comment #32
MobliMic CreditAttribution: MobliMic at Redweb commentedTried to test on simplytest.me against 8.3.x and patch failed. Will reroll
Comment #33
MobliMic CreditAttribution: MobliMic at Redweb commentedAdding rerolled patch for testing
Merge conflict in drupal.js
Comment #34
MobliMic CreditAttribution: MobliMic at Redweb commentedTested on simplytest.me. Patch applied correctly.
Manually clicked around the install. Everything seems to load correctly and the attachBehaviors function is firing correctly. Checked that ajax on tags field was working and quick edit for an article. Ordering of files appears to be correct when combined.
Chrome and IE11
Comment #35
MobliMic CreditAttribution: MobliMic at Redweb commentedUpdating tasks table in issue summary
Comment #36
nod_Little nitpick,
Can be fixed during commit I guess
Comment #37
catchThis looks fine to me for 8.3.x, but needs a change record on the unlikely chance that someone is using library_override.
Also we should clarify the bc policy for location of js files - I think saying libraries_override is @internal would be fine, but don't think we say that yet.
Comment #38
penyaskitoUploading reroll for #36.
I don't get how we should say that libraries_override is @internal, as it's actually an extension API that we don't have a replacement for AFAIK.
It's actually documented at https://www.drupal.org/node/2497313.
If only the change record is needed, I can do that. Just need to be aware if we should do anything with libraries_override.
Comment #39
penyaskitoCreated a draft change record: https://www.drupal.org/node/2830647
Comment #40
nod_That looks good to me. Thanks!
Everything still works.
Comment #42
nod_testbot fail
Comment #44
nod_Another random failure
Comment #47
nod_Comment #48
catch@penyaskito libraries_override itself isn't @internal - we're not going to remove support for it in 8.x
However we can't guarantee that a specific file in a library is going to be override-able in the same way for the entirety of the 8.x cycle (especially not if we commit patches like this).
This is in the same way that hook_form_alter() is an API, but we specifically say the form array passed to the hook can and will change during the cycle.
Comment #49
penyaskito@catch Thanks for the clarification! I reviewed again that the change record draft is clear about this.
Comment #51
catchCommitted/pushed to 8.3.x, thanks!
Comment #52
Gábor Hojtsy