-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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
NextJS Static Site Bundling A Bunch Of self.__next_f.push
Instead Of Raw HTML
#56180
Comments
Hi @loganknecht those scripts are the initialization of the router state on the client. When next navigates from one page to another it does a client side transition (with a fetch to the server to get whatever new markup is required). Unlike in pages router App Router has shared layouts and the client is aware of these layouts and only fetches the part of the page that is not shared. The scripts you see here are the initialization of the client router state so that it can do these navigations. effectively. This includes preserving scroll position when hitting the back button and other aspects of the Router behavior. |
@gnoff - I understand. The goal for my usage of Additionally I do not want to rely on the client router once this artifact has been created. I want to rely on html anchor tags for navigation instead of a client side router. Is there any way to achieve this? |
We have the same problem, our pages are getting too heavy |
This comment has been minimized.
This comment has been minimized.
I'm linking this discussion here. #42170 With React 14, there are now hundreds of injected script tags on relatively small pages. |
I was pretty surprised to realize that "server-side generated HTML" doesn't simply render static HTML, but rather tons of inline script. Especially concerning if you use the app directory on a marketing site where HTML source size can mess up your SEO / page load speed. Is there any fix or workaround for this? |
Similar to #42170 |
Nextjs is far from being optimal to do SSG. If you only want to do SSG, there is great tool out there like Astro. The main problem is how React is design and the way it does the hydration, it need pure JavaScript object to be able to achieve this. Would be great if they could do it base on the HTML element instead of JavaScript, but I don't think they will change the hydration logic of React (at least soon). |
I can see both App router and page router have same issue about double document size |
Let's continue on the discussion: #42170 (comment) |
Link to the code that reproduces this issue
https://github.com/LoganKnechtMagicLeap/NextJS-Static-Example
To Reproduce
Summary
Hello. 👋
I'm in the process of working with the new
NextJS 13
stuff, and to be honest - I'm not really enjoying it.I'm trying to get a static artifact exported, and it kind of works, but it really doesn't.
What's driving me nuts is that the static artifacts it's generating are adding all these unnecessary
self.__next_f.push
lines, that are really unneeded. And, I'm super confused as to what they're there for.Next Config
This is a barebones, vanilla NextJS 13 project.
To reproduce it I created the application by running
Here's my
next.config.js
Source
This is the source page
Output
I'm using a default
NextJS
application, and this is what it's outputtingThis is mostly fine, except it's doing this crazy thing with the
self.__next_f.push
and that's not helping me with my artifacts.Question
How the heck do I get these
self.__next_f.push
to stop being generated and remove them entirely?Current vs. Expected behavior
It injects a bunch of
self.__next_f.push
, when I expect raw HTMLVerify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Static HTML Export (output: "export")
Additional context
I have tried modifying webpack to not use chunking. I have tried forcing client only.
I have my
layout.tsx
file prepended with"use client";
so that every page is supposedly client side only, even though that shouldn't matter.I have tried many solutions, but I just cannot figure out what's going here. This is the default application from NextJS. Why does it need to inject so much with JavaScript??
DX-2261
The text was updated successfully, but these errors were encountered: