Current behavior is for the remote import to be injected in the middle of the file, after the contents of foo.css, so you get this error message in the Chrome dev inspector:
Define @import rules at the top of the stylesheet
An @import rule was ignored because it wasn't defined at the top of the stylesheet. Such rules must appear at the top, before any style declaration and any other at-rule with the exception of @charset and @layer.
Expected behavior
The @import should probably be hoisted up to the beginning of the final generated CSS file.
The only workaround is to either put these imports in <link> tags in the _document.tsx head, or to have a imports.css and put all your remote imports in that, and include that first in the _app.tsx. But those seem like hacks, and makes it hard to have reusable CSS files/modules defined in libraries which themselves reference remote CSS stuff. For example, my UI library references CSS fonts and katex stuff and some other remote stuff, and then I load it in my Next.js app with @import '@mylib/styles/x.css, and that itself has remote imports buried deep. So somehow this should work.
Verify canary release
[X] I verified that the issue exists in the latest Next.js canary release
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
In the link I provided, remove the line at _document.tsx where I add the google font. Locally, it works when loading from the remote import, but in production it doesn't work, and the font is missing b/c of that error in the image I showed above.
Link to the code that reproduces this issue
https://github.com/textsurf/tune.land/tree/7900104fe0932ce8780b0c26985f95b6a492d97b
To Reproduce
Have an app which loads stylesheets like this:
Add this to
_app.tsx
:Current vs. Expected behavior
Current behavior
Current behavior is for the remote import to be injected in the middle of the file, after the contents of
foo.css
, so you get this error message in the Chrome dev inspector:Expected behavior
The
@import
should probably be hoisted up to the beginning of the final generated CSS file.The only workaround is to either put these imports in
<link>
tags in the_document.tsx
head, or to have aimports.css
and put all your remote imports in that, and include that first in the_app.tsx
. But those seem like hacks, and makes it hard to have reusable CSS files/modules defined in libraries which themselves reference remote CSS stuff. For example, my UI library references CSS fonts and katex stuff and some other remote stuff, and then I load it in my Next.js app with@import '@mylib/styles/x.css
, and that itself has remote imports buried deep. So somehow this should work.Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
In the link I provided, remove the line at
_document.tsx
where I add the google font. Locally, it works when loading from the remote import, but in production it doesn't work, and the font is missing b/c of that error in the image I showed above.