[Bug?]: Unexpected Link Element Generation for Stylesheet Imports in Production Environment #1585
Closed
2 tasks done
Labels
bug
Something isn't working
Duplicates
Latest version
Current behavior 😯
Approach 1: Using
onLoad
propI tried using the
onLoad
prop to update therel
attribute when the stylesheet has finished loading:However, this throws an error:
Approach 2: Using
ref
andonMount
I then tried using a
ref
and updating therel
attribute in theonMount
function:I'm not completely certain whether doing the work inside
onMount
will replicate the same behavior as the HTMLonload
attribute would, but this works as expected in the development environment, but not in the production environment.Approach 3: Using Signals as refs
I also tried using Signals as refs:
Both Approach 2 and 3 work as expected in the development environment. The initial document shows the
link
withrel="preload"
, and the attributes are updated as expected when inspecting the rendered document.However, in the production environment, Solid start will include a link tag with
rel="stylesheet"
for the Explicit Url Import, which negates the initial preload and blocks the rendering of the stylesheet, overriding the preload implementation.Here is a screenshot of the initial document sent from the server in the production environment:
Any guidance on how to correctly load a stylesheet asynchronously in Solid, particularly in a production environment, would be greatly appreciated.
Expected behavior 🤔
When importing stylesheets on the client side using standard imports like
import "~/styles/base.css";
orimport "~/styles/cursors.css";
, Solid correctly compiles all imports together into a singleclient-*.css
link element, such as<link href="/_build/assets/css/client-Bg1X780_.css" rel="stylesheet" fetchPriority="high"/>
.However, when the stylesheet is imported using
?url
(explicit URL imports from Vite), the handling of the stylesheet should be deferred to the URL itself. This is because explicit URL imports are intended to return the URL of the imported asset as a string, and not to automatically include the asset in the markup.In this case, Solid should not automatically generate a
<link>
element withrel="stylesheet"
for the imported URL. Instead, it should be left to the developer to decide how to include the stylesheet in the markup, such as creating a<link>
element with the desired attributes.This would allow for more control over the loading and application of stylesheets, and would prevent issues like the one described, where the automatic generation of a
<link>
element withrel="stylesheet"
negates the initial preload and blocks the rendering of the stylesheet, overriding the preload implementation.Steps to reproduce 🕹
Steps:
styles
directory, for examplebase.css
andcursors.css
.client-*.css
link element, such as<link href="/_build/assets/css/client-Bg1X780_.css" rel="stylesheet" fetchPriority="high"/>
.Link
element from@solid/meta
for the imported URL:Link
element should showrel="preload"
in the initial document, and the attributes should be updated as expected in the rendered document.<link>
element withrel="stylesheet"
for the imported URL, but it does. This negates the initial preload and blocks the rendering of the stylesheet, overriding the preload implementation.Context 🔦
I'm trying to load a stylesheet asynchronously using the
Link
component in Solid. I've tried several approaches, but all are producing unexpected behavior in the production environment.Your environment 🌎
The text was updated successfully, but these errors were encountered: