silverstripe / silverstripe-asset-admin

Silverstripe assets gallery for asset management
BSD 3-Clause "New" or "Revised" License
19 stars 78 forks source link

Forcing JS to the head breaks AssetAdmin #1349

Open p0lar-bear opened 1 year ago

p0lar-bear commented 1 year ago

I recently tried updating a site from earlier in 4.x and found that, after fixing myriad other issues from an outdated app codebase (all my fault and not relevant here), the AssetAdmin view would come up blank. I noticed two errors being thrown in the browser console and investigated.

Line 11 of client/src/boot/registerQueries.js has a bit of a side-effect in that document.body is evaluated immediately when the webpack bundle script is loaded. My site config for some long-forgotten reason had Requirements::set_write_js_to_body(false) in the config. Because of this, the boot script for AssetAdmin would throw an error and nothing else would happen. Something in the vendor scripts would also do the same.

While I was able to fix this by removing that Requirements config call, I feel the better solution here is to move the isLegacy definition and assignment to inside of the registerHandlers function - the value isn't being exported or needed outside of that function.

sb-relaxt-at commented 1 week ago

Thanks a lot, I just got the same issue. Error message in the console has been: "Cannot read properties of null (reading 'getAttribute')" Moving the Requirements statement to the PageController#init seems to be a solution.