-
Notifications
You must be signed in to change notification settings - Fork 27.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected onLoad attribute behaviour in next/head #12984
Comments
Did some testing on other devices: iPad OS and iOS have no issues. Seems like it only occurs on macOS but I can’t verify Windows. I've tried removing the Theme UI hook to see if this was the root, but it appears to make no difference. |
As an update I've tested this new approach, which is a mix of font-loading performance suggestions I've found online: <link
rel="preload"
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap"
as="style"
/>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap"
rel="stylesheet"
media="print"
// // Next.js doesn't like this but it allows us to load CSS asynchronously
// @ts-ignore
onLoad="this.media='all'"
/>
However a slight flash still remains and TypeScript doesn't like my I have a hunch that something in Update #1 - I've tried |
After some further investigation with @csswizardry, we found that when JS is disabled the What's even stranger is once JS is enabled, this behaves as expected but moves further down the This leads me to think |
|
Thanks for getting back to me @timneutkens, I was just about to update this issue as I've managed to build a workaround solution in the meantime: I'd still prefer to use |
Copied from #16065 where I have a problem related to what OP is trying to do. If I want to use <link rel="preload" href="https://..." as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://...></noscript> to make loading CSS async, that does not work because I'd have to rework that to using onLoad with a function, but that function is never executed. So
|
Did you find a solution to this? I have the same need. |
@dsacramone Nope, I did not find anything yet. Maybe the @tsignore annotation referenced in the 'fix build' commit above works? |
@timneutkens At least on the client, the react elements are converted to regular DOM elements and all props are converted regular HTML attributes: next.js/packages/next/client/head-manager.ts Lines 9 to 27 in 85499b5
This causes the scope of the function to be lost as it is converted to a string with the |
Following seems to work
|
Next.js comes with Font Optimization out-of-the-box now, this should not be necessary. Please check out our docs: https://nextjs.org/docs/basic-features/font-optimization |
@balazsorban44 Please reopen this issue. There are several other use cases besides fonts that would benefit from the |
Could someone add a reproduction that I could clone and test with the newest version of Next.js? (as of writing I'm happy to investigate further then. |
This issue has been automatically closed after 30 days of inactivity with no reproduction. If you are running into a similar issue, please open a new issue with a reproduction. Thank you. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
In my project
raam
I'm tying set"Inter"
as my font by linking to a stylesheet from Google Fonts.In
Head
(a component that extendsnext/head
) I'm using:(note the
preconnect
to the actual font assets, then thedisplay=swap
which is intended to show the fallback font until the loaded font is swapped in)When I then go to view the page (in Firefox particularly) I see a flash of unstyled/invisible text:
https://raam-git-chore-inter.joebell.now.sh/
Screenshots
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Expected behavior
The system font is seen first, and 'swapped' to Inter on load.
System information
Additional context
I appreciate there's a lot of variables here: Theme UI, Google Fonts, Now.sh, Next.js, but it would be good if we can figure out the root cause here for others using Next.js. If it's something that could be resolved by adding some documentation I'd be more than happy to do so.
Thanks again for all of the team's hard work on Next.js, it's a real pleasure to work with
Prior reading
Example
The text was updated successfully, but these errors were encountered: