Next.js Discord

Discord Forum

Duplicate data source in html

Unanswered
Giant ichneumon wasp posted this in #help-forum
Open in Discord
Giant ichneumon waspOP
I've created a very basic nextjs project and, I see duplicate list in the html/js source. Is that normal? Should not be I think.

18 Replies

Giant panda
That’s just the way React serializes the VDOM. It improves speed at the expense of size. That’s why data is duplicated in the serialized output
Giant ichneumon waspOP
I dont want to believe this. That was not the case with next 12. I've checked a demo template site, and no problem with that. view-source:https://commerce-v1.vercel.store/
Rootlayout is rendering twice, maybe that's the issue. There was an open issue with double(parallel) rendering of root layout, that have no solution
Giant panda
That was not the case with next 12
Because RSC are architecturally entirely different. And Next 12 didn't send a snapshot of the VDOM down the wire.
Giant ichneumon waspOP
Unfortunately, I could not verify same problem with available RSC next demo projects. The one I posted previously, and the one here: https://github.com/vercel/next-react-server-components
I know there must be a javascript data source, and html created from this data list whenever needed, but the javascript source here created twice and makes no sense
Are you running in dev mode?
Giant ichneumon waspOP
Both mode produce the same result, but I step forward as follows:
Do you get the same behavior if you move this logic to a page instead of your root layout?
Giant ichneumon waspOP
If I create the list in the page instead of creating list in the layout page, everythnig seems fixed. So when a datasource/fetch is done in layout(or at least rootlayout), the source list is created twice, if it is done in page created single as expected. I dont know if this is a bug
@Marchy Do you get the same behavior if you move this logic to a page instead of your root layout?
Giant ichneumon waspOP
Ohh I just was writing about it! Why?
@Giant ichneumon wasp Ohh I just was writing about it! Why?
layouts are for layouts. pages are for fetching. generally speaking dont fetch in a layout
Especially the root layout
Giant ichneumon waspOP
I will make further tests to check on layout and rootlayout , pages and components. Eventually I need dynamic data as a menu on layout. Will keep you update soon
Giant ichneumon waspOP
I've done some further tests; other than the page; if I place the JavaScript array list(can be a fetch or not) in any type of layout, even the list is in the component but is consumed by the layout; the list is duplicated in page source. The only place where it is not duplicated is the page.
I believe this should be resolved; as lists/dynamic data in layout such as menu, product list etc. can be used most time. I'll open up an issue on github
Giant ichneumon waspOP