silverstripe / silverstripe-admin

Silverstripe Admin Component
BSD 3-Clause "New" or "Revised" License
25 stars 92 forks source link

Requirements calls made with AJAX requests do not register correctly in admin #897

Open robbieaverill opened 5 years ago

robbieaverill commented 5 years ago

Affected: SS ^4.0

This is an issue that has been happening for a while, but I don't remember seeing an issue for it now that I think about it, so I'll raise one here.

Basically, if you define a Requirements call for JavaScript (mainly) and load the section of the admin area that uses that via an AJAX request (e.g. clicking into a section which loads with PJAX) then the Requirements calls does not get added to the window, and the JavaScript is unavailable.

Example:

class Page extends SiteTree
{
    public function getCMSFields()
    {
        Requirements::javascript('my/module: client/dist/bundle.js');
        return parent::getCMSFields();
    }
}

If you load navigate into Pages > a page > CMS fields by clicking around, the panels are loaded with PJAX, and the bundle request is send in the network tab, but is not added to the window, so never executes. This doesn't seem to affect CSS requirements though.

As a workaround (in every module I've worked on that has this kind of logic in it) we add all requirements globally to LeftAndMain.extra_*_requirements via configuration so it's always available.

This worked in SS3, but something has changed in SS4 that breaks it.

robbieaverill commented 5 years ago

I've left this for someone else to triage

chillu commented 5 years ago

I can imagine this breaks quite a few modules, particularly extra form fields. Not sure how long that's been the case for, but I'm pretty sure this used to work in SS 4.x in the early days...

robbieaverill commented 5 years ago

I don't remember this ever working in SilverStripe 4, we've always worked around it while upgrading supported module =/