Plain string for <Link onload="..."> shows warning

I want to preload google fonts in the root.tsx like so:
<Link
rel='preload'
href="https://fonts.googleapis.com/..."
as='style'
attr:onload="this.onload=null;this.rel='stylesheet'"
/>
<Link
rel='preload'
href="https://fonts.googleapis.com/..."
as='style'
attr:onload="this.onload=null;this.rel='stylesheet'"
/>
yet, typescript can't seem to find that attribute, i.e.:
Type '{ rel: string; href: string; as: "style"; "attr:onload": string; }' is not assignable to type 'IntrinsicAttributes & LinkHTMLAttributes<HTMLLinkElement>'. Property 'attr:onload' does not exist on type 'IntrinsicAttributes & LinkHTMLAttributes<HTMLLinkElement>'
How can I use attr: to make clear I want to set my attribute as plain text?
8 Replies
Bersaelor
Bersaelor10mo ago
mhmm so maybe typescript doesn't understand attr: ? Because it still says that attr:onload does not exist ah, interesting, i didn't know that mhmm, I mean I guess solid-js expects the onload to be a handler, i.e.
onload={ () => {
this.onload=null;
this.rel='stylesheet
}
}
onload={ () => {
this.onload=null;
this.rel='stylesheet
}
}
but that didn't work for me root.tsx(27, 25): An outer value of 'this' is shadowed by this container. i just copied this code from somewhere when I added preloading to the fonds, mhmm, so it saysAn outer value of 'this' is shadowed by this container. , but I think thats exactly want I want? the this should be the <link> attribute in question i.e. I want the container to shadow the outer this (which would be the root.tsx , right?) so, this seems to be a comment structure:
<link rel="preload" as="style" onload="this.rel='stylesheet'" href="http://www.example.com/style.css">
<link rel="preload" as="style" onload="this.rel='stylesheet'" href="http://www.example.com/style.css">
when using a preload-link first the rel is preload and when it finishes loading it is changed to stylesheet
Bersaelor
Bersaelor10mo ago
web.dev
Defer non-critical CSS
Learn how to defer non-critical CSS with the goal of optimizing the Critical Rendering Path, and improving FCP (First Contentful Paint).
Bersaelor
Bersaelor10mo ago
With this information, optimize your CSS so that the browser starts processing critical styles immediately after page loads, while deferring non-critical CSS for later:
but as they also said
In this guide, you used vanilla code to implement this optimization. In a real production scenario, it's a good practice to use functions like loadCSS, that can encapsulate this behavior and work well across browsers, and can support a Content Security Policy that may not allow inline onload JavaScript.
loading fonts from googlefonts in a blocking way adds extra blocking 600ms - 1000ms on mobiles devices for first page load would we still get into trouble with CSP's using event.target ? noice, thank you for reminding me of event.currentTarget int he example they do e.currentTarget.onload = null; would that also remove the handler in solid ?
Bersaelor
Bersaelor10mo ago
i mean it seems to work in localhost , let's see hwta happens if I deploy and SSR it
No description
Bersaelor
Bersaelor10mo ago
I can also see it changing when I have the devtools open and look at the lines while refreshing thats not my IDE, thats chrome devtools screenshot of it working (on localhost) so this is the code:
<Link
rel='preload'
href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap"
as='style'
onload={(e) => { e.currentTarget.rel = 'stylesheet'; }}
/>
<Link
rel='preload'
href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap"
as='style'
onload={(e) => { e.currentTarget.rel = 'stylesheet'; }}
/>
Bersaelor
Bersaelor10mo ago
and this is what the result looks like in chrome
No description
Bersaelor
Bersaelor10mo ago
SolidStart Beta Documentation
SolidStart Beta Documentation
Early release documentation and resources for SolidStart Beta
Bersaelor
Bersaelor10mo ago
i'm not sure how that works in solid same result I could try adding a ref and adding an observer in onMount. But wouldn't that be super verbose for that one-liner? i see, well you told me and the tutorial above said so, so you two are probably right pretty sure that is the reason why Safari doesn't swicth from preload to stylesheet the rel attribute is not switched on safari but <link rel="stylesheet preload" as="style" href="style.css" > seems to work too, let's see what https://pagespeed.web.dev says when I deploy that yup, seems that fixed it too (pagespeed.web.dev no longer complains about blocking font loads) nope, sorry just saw this question, not doing any pushing
Want results from more Discord servers?
Add your server
More Posts
why is it possible to use singletons in astro but not solid-start?when ssr'ing solid with solid-start it's advised not to simply import and export signals/stores, akaPlease, HELP with SSRI have no previous experience with SSR and I am just starting my journey with Solid.js but looking aPocketBase Auth with Context doesn't track storeI'm trying to create a PocketBase AuthContext that I may add to my app, so that in the future if I wHow can I populate HTML on the server with db data before sending it to the clientHello - i am new to solidstart and today as I was attempting to port a nextjs app into solidstart I Proper implementation of a timer/stopwatchI am struggling to understand how to properly implement a timer in a reactive library/framework likeNo Vercel LogsHi! I've deployed a solid-start app using Auth.js which I originally generated using create-jd-app tPrevent re-render <table> element when changing array in store.is it possible to prevent re-render whole table element when i splice element from array in store? TIs <HydrationScript/> required even if I'm not utilizing SolidJS' SSR?In my project, the `Uncaught ReferenceError: _$HY is not defined` is shown when I'm not using `<HydrBuilding with SSR false starts (and doesn't close) listenersIn my app I create a WebsocketServer on Port 3001. If I run `npm run build` with default SSR settingSolidJS: Manually using SSR with v8?Hi, I am working on a project which has a PHP back-end, but which has access to a PHP V8 (https://g