Revert "[4.0] Wrong order for attachActiveAssetsToDocument in MetasRenderer.php"#24858
Revert "[4.0] Wrong order for attachActiveAssetsToDocument in MetasRenderer.php"#24858wilsonge merged 1 commit intojoomla:4.0-devfrom
Conversation
This reverts commit 0e95df6.
|
Hmm, will this not result in a pull request ping pong? After this one here which reverts #24848 will be merged, @joeforjoomla makes a new PR to revert this one here and so restore #24848 , and then you make again a PR to revert that and so on and so on? And @wilsonge will merge them all? ;-) This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24858. |
|
@wilsonge Please decide which one is right. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24858. |
|
the fix #24848 more like a cosmetic changes, and has a big drawback |
|
Maybe in addition to this PR it needs a new event "OnBeforeAssetAttach" (or so) at the place where #24848 has moved the "onBeforeCompileHead" to, so all are happy? |
|
such event already exist, called |
@joeforjoomla you forgot about a plugins that may want to alter the $doc, It more break the logical behavior of the onBeforeCompileHead |
So how have you did it till now? If you did it till now you will be able to do it even in the future because nothing changes. |
|
And however if you really care about this, my suggestion was to add a new event onAfterCompileHead that would be the most logical way. So close this PR and make a new one in this sense. |
nope, unfortunately, while your problem |
Nope, this event is not used to alter head data, but to add/remove assets before that the document head is compiled. |
I have not a problem. The problem here is the most logical way that things are supposed to work. |
yeah sure, tell me then, what is used? |
|
This event was used to alter head data in the past but wrongly and because there has never been a better way and a onAfterCompileHead. Altering head data here is a sort of 'hack' |
Actually, that is altering the The problem isn't pull request ping pong or workflows. The problem is at an architectural level the web asset API is not compatible with the Document API, and that with the web asset API in place as a parallel and standalone thing you have two different places where assets can be registered to be "enabled" in the document (I still hate that terminology). Attaching the web asset data to the document before the compile event means you can't touch that API anymore, and you're stuck reverse engineering the resulting scripts and stylesheets arrays inside the document to find everything an asset includes if you need to do something with it (so here's hoping you don't have a "complex" asset in your chain). Attaching the web asset data after the compile event means something is firing off after plugins have had their last chance to alter the Document (and no, it doesn't really matter here that the asset API has its own event, that is an event specific to that API). Engineering wise, you HAVE to get everything on a single path, SOMEHOW. From a core perspective, you really MUST consider the Document frozen after
Bad idea. At that point you're dealing with string parsing, not data objects. Just use |
|
I think, at current state,
that is what actually I tried to say :)
Technically it become "frozen" itself (but silently), because any modification after that event will not affect the output. |
|
Yes the problem is at an architectural level. By the way even relying on the onBeforeCompileHead to alter docs through plugins has always been wrong. It's subject to race condition of the order of execution of plugins, additionally Joomla has a addScript method but not a removeScript method. Let's suppose that you have system plugin 1 and system plugin 2. The plugin 1 adds a script, the plugin 2 wants to remove that script from the document. This only works if the plugin 1 is executed before plugin 2. To have a similar behavior working in a reliable way we should split this process into 2 events, otherwise there is the bad solution... parsing string during the onAfterRender. |
It is not wrong, You just made assumption that it only one way to add scripts, and have stick to it, but it is not only way. |
Indeed it's wrong. You can't rely to plugins sorted. A user is free to sort and change the order of plugins in backend, so relying on this is crazy. What you need to accomplish what you have in mind, would be something like this: |
this is BC for existing plugins, and will cost much to them, while moving your
If order are important then it will be in plugin description/documentation. |
|
The issues you're describing about plugin order of operations are an issue of any event dispatching system. It's why event listeners can't make assumptions about what order they are running in, and one of the umpteen thousand reasons why I have issues with how core manages its plugin integrations. |
|
Hmm, do I understand right that if this PR here is not accepted, the change from #24848 is some kind of BC break? If so, then maybe https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4 needs to be updated? |
|
@richard67 #24848 is not kind of BC break. Reverting with this PR would be kind of BC break |
|
Ah, so in case if this PR here gets accepted, then it has to be mentioned in docs https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4, too, I see. |
|
@richard67 if this is accepted, and let's hope that it is because #24848 is not only a B/C break but also a huge break in functionality, documentation does not need to be updated. WebAsset library is new in 4.0 so there was no B/C break in the first place. @joeforjoomla just needs to understand that he's using it incorrectly. This has already been explained by @Fedik, who is essentially the author of WebAsset library. |
|
Well, it seems that i'm wasting my time trying to explain how an architecture should be supposed to work. By the way if someone should move something to the onWebAssetBeforeAttach that is new in 4.0 in order to avoid an exception and fatal error, yes this is a B/C break and must be documented in https://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_4, |
yes, because it will be not possible to get all scrits/styles at
Mainly code review. and make a system plugin event: function onBeforeCompileHead()
{
var_dump(JFactory::getDocument()->_scripts);
}In the dump you should see |
|
I have updated, description, added testing. @wilsonge please have a look. I think it important issue. To fix that issue we can just change a recommendation, to use |
|
I have tested this item ✅ successfully on 92ec65e Output on frontpage without this PR applied: Output on frontpage with this PR applied: This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24858. |
|
I have tested this item ✅ successfully on 92ec65e This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24858. |
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24858. |
|
Seems like more people are in agreement than disagreement with this revertion so merging |
Reverts #24848
That changes has more drawback than actually fixing (#24848 (comment))
Critical to me: the changes in #24848 not allow to alter $doc anymore, because at
onBeforeCompileHead$doc has incomplete set of js/css/options.To enable an asset there many way, they can be enabled in layout, in all events between
routeandrender.But alter $doc js/css/options possible only at
onBeforeCompileHead.Testing
Add to any system plugin an event:
Expected:
You should see
paths/to/core.min.jsIn the dump output.Actual:
paths/to/core.min.jsnot exist in the output