next.js: Dynamic pages stuck on loading.tsx when JavaScript is disabled

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Home
    Binaries:
      Node: 18.16.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.4.3
      eslint-config-next: 13.4.3
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Data fetching (gS(S)P, getInitialProps), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/relaxed-davinci-o1i9yl?file=%2Fapp%2Fpage.tsx%3A5%2C15

To Reproduce

Create a page that dynamically fetches some data on every request, either via export const revalidate = 0 or the no-store configuration on fetch.

Set up a global loading.tsx in the app folder.

Build and run the project.

Disable JavaScript in the web browser and open the dynamic page. The loading.tsx page is shown indefinitely.

Note: You can disable JavaScript in Chrome by pressing F12 to open the Chrome dev tools. Then press Ctrl + Shift + P and search for “disable JavaScript”.

Describe the Bug

When you open a dynamic page with JavaScript disabled, you get stuck on the global loading.tsx indefinitely.

This also means that this page is effectively invisible to web crawlers, which kills SEO for that page.

Expected Behavior

The page should be loaded even with JavaScript disabled.

Which browser are you using? (if relevant)

Google Chrome

How are you deploying your application? (if relevant)

Locally and on Vercel

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 37
  • Comments: 22 (3 by maintainers)

Most upvoted comments

I’m a bit puzzled by the default behavior of Next.js regarding steaming components. By default Next.js renders the content of async components to a hidden div with a unique id:

Screenshot 2023-06-09 at 15 53 29

This div is invisible and rendered almost at the bottom of the body and then the script mentioned above kicks in to place it in the correct position.

My question is, why not render it at the correct position in the DOM, why at the bottom? If Next.js did that people with no JavaScript enabled would still see the content at the correct position, without any JS needed to place fully formed HTML (with data) into the correct position.

Is it some technical limitation?

Similar behavior. Can confirm. When JS is disabled, loading state is displayed forever. Usually, a loading toggle is covered by javascript, but it also can be achieved by CSS as well

I found the same case here and noticed some points in #66244. I will also put it here:

  • The content loaded via SSR has the HTML code of the content not displayed, but this is hidden via CSS by a [hidden] tag together with the loading.tsx. Perhaps it would be ideal, instead of removing the [hidden] tag, to start with the default view and replace this content later if necessary.

  • It will always only occur on pages with page.tsx using async type return, for example if you need to fetch an api with await on the server side, you will probably run into this problem.

  • Even if I remove loading.tsx, the content is still invisible.

  • Because the content is invisible, the impact on core web vitals occurs, mainly in FCP, LCP and INP. Ideally, immediate display would be better, because hydration already takes care of and guarantees that pages do not change the content between the SSR and client-side first processing. Even on pages with Javascript activated normally, there is still an impact on display performance, greatly taking away the advantage and purpose of using SSR.

  • In some very rare and intermittent cases, even with javascript disabled, the page starts rendering correctly without displaying loading.tsx. I couldn’t find out why or the cause of this.

Summing up and reinforcing, I believe that the approach with the [hidden] tag is not ideal, perhaps we can create an approach in which the content starts visible (without [hidden]) and that will be replaced later by the result of the render/hydration, I don’t think so would greatly alter the current structure and solve the problem.

The issue still persists 😔. What is interesting, though, is that it appears to behave inconsistently - based on the time the server component needs to return the response.

I created a page with this content:

export default async function PageTest() {
  return new Promise((resolve) => 
   setTimeout(() => resolve(<div>Hello World!</div>), 100)
  );
}
  • If I change the timeout to 1-5 ms, the content is rendered straight away.
  • If I change it between 5-10 ms, sometimes the suspense loading fallback is displayed, and sometimes the content is rendered straight away.
  • If it’s more than 10 ms, the suspense fallback is always displayed.
  • If I remove all loading.tsx files from the project, the content is always rendered straight away no matter the timeout.

Is there some config that could be changed to accommodate for slightly slower responses? In my case, I’d rather delay the response by 100 ms than have an ugly loading screen displayed for just a few milliseconds. 🙏

Other crawlers will also see the content.

Only if they execute JS? Or can they still see the content without JS?

yes, I actually have the same question. I’m facing a similar issue: if I disable JS, the navbar and footer are loading but server-side content within page.tsx is not rendering. Instead ,the loading.tsx is the one rendered.

Both this thread and the documentation are a little confusing to me.

JavaScript is indeed required to render streamed UI on the browser.

This isn’t clear in the docs, in fact they are a little misleading, since they state

Since streaming is server-rendered, it does not impact SEO. [0]

I understand that crawlers like Google’s can run JavaScript, which makes this claim partially true, but the sentence is misleading - the reason SEO is unimpacted is that bots can run JavaScript, it is NOT that the page requires no client-side JS to render, which the sentence seems to imply.

This process, known as “hydration”, uses ReactDOMClient.hydrateRoot.

I hope this is incorrect! My understanding (and hope!) is as follows: next.js ships a tiny script, separate from the client-side bundle, which is responsible for switching out the loading UI to the server-rendered HTML as it comes in. This requires very little client-side ‘effort’ and works for server-side components below the suspense boundary, which the client never hydrates! Hydration is a separate step, specific to client-side components, which requires the full client side bundle and a separate client-side render pass, to reconcile server-side HTML with client-side DOM nodes, and make components interactive.

If streaming required hydration to work, there would be little benefit over pure client-side rendering. But it would be great if the docs were clearer. The only sentence which alludes to this is a little light on the details, especially given the confusing information about SEO:

By using Suspense, you get the benefits of Streaming Server Rendering - Progressively rendering HTML from the server to the client. [0]

[0] https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense

EDIT: I am now unsure whether streaming is helpful at all compared to client-side rendering.

I’m comparing the two on a production application by using https://www.webpagetest.org/ and looking at the screenshots, + at LCP. For the client-side test, I am forcing client-side rendering using

const [render, setRender] = useState(false)
useEffect(() => setRender(true))

return render ? children : null

Client-side rendering: LCP ~9s Streaming : the layout (header + footer, above the suspense boundary) appears at ~2s with a loading spinner, LCP ~9s (no better than client-side rendering, which is unexpected and disappointing!) Fully server-side rendered (obtained by removing loading.tsx): LCP ~3s

It feels like when streaming, nothing is visible until the client-side bundle is downloaded, parsed, and executed, which is not what I would expect, and not what the documentation suggests (“By using Suspense, you get the benefits of Streaming Server Rendering”). It looks like the only benefit of streaming is that it lets you use data from server components. Why does the page take 9s to display everything, despite the full HTML streaming from the server being available after 3s?

I agree, streaming seems to be causing nothing but headaches for no advantage. I still get the loading.tsx spinner appearing on initial page load for an SSR page.

At this point I feel like my only option is going to be to migrate entirely away from Next just so I can turn off streaming rendering.

Guys if anyone has this issue maybe on a specific page like we did, the trick to fix the initial loading without the loader popping up at first is to put all your requests in a single Promise, we had one additional request not sitting in Promise.all() and it screwed everything up on a specific page.