You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I also have assets/article.js in which I use photoswipe that I have installed using importmap:require (it can also be done using NPM, I have tried both ways):
The fact, that third party CSS is embedded inside the importmap as JS causes inconsistency in the way the CSS is loaded
If I use SPA of some sort (I am using signalizejs, not tested with Stimulus) that redraws parts of pages in which the module is included, it won't trigger the CSS to be loaded on ajax redraw of the page so I have javascript loaded but not the CSS (local CSS however is loaded correctly).
Also, If I turn off JS, the CSS is not loaded
The CSS in SPA works only through the native link for the local CSS or through link element as shown in "working solutions".
Not working solutions
asset('photoswipe/dist/photoswipe.css') function to create the link element => not working
Moving photoswipe/dist/photoswipe.css into local css file assets/article.css:
@import'photoswipe/dist/photoswipe.css'
And import it in js:
import'./article.css'
This causes 404 because if I load the third party CSS in local CSS because the file path it is not acessible/properly mapped (which is probably correct behavior as it is not a javascript module)
Tried to import assets/vendor/photoswipe/dist/photoswipe.css (if installed using importmap:require) file directly in JS. Not working, still compiled into the weird JS:
Tried to import assets/vendor/photoswipe/dist/photoswipe.css (if installed using importmap:require) by article.css that is imported in article.js. Not working at all.
Working "solutions"
Install it using importmap:require and access it using
Machy8
changed the title
AssetMapper: Inconsistency while loading CSS causing SPA apps not working properly.
[AssetMapper]: Inconsistency while loading CSS causing SPA apps not working properly.
Jun 29, 2024
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
7.0
Description
I am using https://symfony.com/doc/current/frontend/asset_mapper.html for loading CSS and JS on my website.
The Example
I have
assets/app.js
that imports local CSS:This is generated into the html as:
I also have
assets/article.js
in which I use photoswipe that I have installed usingimportmap:require
(it can also be done using NPM, I have tried both ways):This is converted into:
The problem
The fact, that third party CSS is embedded inside the importmap as JS causes inconsistency in the way the CSS is loaded
link
element as shown in "working solutions".Not working solutions
asset('photoswipe/dist/photoswipe.css')
function to create thelink
element => not workingphotoswipe/dist/photoswipe.css
into local css fileassets/article.css
:And import it in js:
This causes 404 because if I load the third party CSS in local CSS because the file path it is not acessible/properly mapped (which is probably correct behavior as it is not a javascript module)
assets/vendor/photoswipe/dist/photoswipe.css
(if installed usingimportmap:require
) file directly in JS. Not working, still compiled into the weird JS:assets/vendor/photoswipe/dist/photoswipe.css
(if installed usingimportmap:require
) byarticle.css
that is imported inarticle.js
. Not working at all.Working "solutions"
importmap:require
and access it usingBrowser
All on Ubuntu 22
How to reproduce
I have explained that above.
Possible Solution
Every CSS loaded using asset-mapper should behave the same and should be converted into native
<link>
element so it works with or without javascript.Additional Context
No response
The text was updated successfully, but these errors were encountered: