question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When stylesheets are imported into pages/_app.js, the server responds the page without styles

See original GitHub issue

Bug report

Describe the bug

When stylesheets are imported into _app.js, on the client side everything looks as expected, but when a first load is done (SSR) the server responds unstyled page.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

git clone https://github.com/turrione/nextjs-mdbreact.git
yarn install
yarn dev

Notice that when a first request is made, the response preview is unstyled.

The only way I have found to receive the styled page from the server side is adding the stylesheets in the public folder and adding the links <link rel="stylesheet" href="/css/global.css" /> inside the next/head in the Layout component

It can also be reproduced with the example cms-wordpress (with tailwind)

Expected behavior

When the server takes over the rendering, it responds with the styled page, as seen on the client side.

Screenshots

Server response importing the CSS file within pages/_app.js (like documentation says)

Captura de pantalla 2020-06-17 a las 15 01 16-min

Server response adding stylesheets link in next/head

Captura de pantalla 2020-06-17 a las 15 05 20-min

System information

  • OS: macOS
  • Browser: Chrome & Safari
  • Version of Next.js: 9.4.0 & latest
  • Version of Node.js: 12.8.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
turrionecommented, Jun 18, 2020

Static css assets seem to load. Do you have a screenshot related to production build? With the dev tools preview?

The same result that tywmick https://github.com/vercel/next.js/issues/14286#issuecomment-646237050= has published

@tywmick of course the search engines look and consider the styles. Think that only using css you can do things that go against the good practices indicated by search engines. Such things as hiding text from the user, forcing click on links by hiding them and a huge etc. Search engines need to analyze styles to make sure they are not showing spam, malicious or simply irrelevant content in top positions. In short: we need styles to come from the server side.

0reactions
github-actions[bot]commented, Nov 30, 2022

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template), but you can also use a tool like CodeSandbox or StackBlitz.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). “example.com”, “n/a”, “will add later”, etc. are not acceptable links – we need to see a public codebase. See the above section for accepted links.

What happens if I don’t provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment “I have the same issue” without repro steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren’t you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js Global CSS cannot be imported from files other than ...
js, and it was previously working? I've moved my main.scss import to the pages/_app.js page, but the styles still aren't coming through. This ......
Read more >
import - CSS: Cascading Style Sheets - MDN Web Docs
The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top...
Read more >
Basic Features: Built-in CSS Support - Next.js
To add a stylesheet to your application, import the CSS file within pages/_app.js . For example, consider the following stylesheet named styles.css :...
Read more >
How to Link CSS to HTML Files in Web Development - Hostinger
Although external CSS helps make the web development process easier, there are a few things to keep in mind that HTML pages might...
Read more >
Style Sheets in HTML documents - W3C
Style sheets represent a major breakthrough for Web page designers, expanding their ability to improve the appearance of their pages.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found