You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
Recently, I migrate my blog to Next.js app router from page router. And I noticed source of preview component is pre-rendered at server-side! I find nobody saying about this, write this issue for helping who struggling for SEO(Is there any other communication channel?)
And here is my code using app router(server-component).
Code
page.tsx
// no 'use client'// this is server-componentasyncfunctiongetPost(id: number): Promise<IPost>{constres=await(fetch(`${API_BASE_URL}/post/${id}`));returnawaitres.json();}exportdefaultasyncfunctionPage({ params }: {params: {id: string;};}){constpost=awaitgetPost(Number(params.id));return<div>{/* title, subtitle, .... */}<MarkdownViewersource={post.body}/></div>}
MarkdownViewer.tsx
'use client';// <- must be addedimportMarkdwonViewfrom"@uiw/react-markdown-preview";exportdefaultfunctionMarkdownViewer({ source }: {source: string;}){return(<divclassName="markdown-body"><MarkdwonViewsource={source}/></div>);}
The reason is maybe difference from dynamic import and 'use client'. When using dynamic import there is no element for rendering and redering start in browser. However, 'use client' is not meaning perfect client side rendering, It pre-render elements which next.js can pre-render. (docs)
But I don't know how next.js decide the boundary of pre-render. If anyone knows the answer about this question, please talk about that! Thanks.
The text was updated successfully, but these errors were encountered:
Hi!
Recently, I migrate my blog to Next.js app router from page router. And I noticed source of preview component is pre-rendered at server-side! I find nobody saying about this, write this issue for helping who struggling for SEO(Is there any other communication channel?)
Before code was as same as Support Next.js #446 using dynamic import.
And here is my code using app router(server-component).
Code
page.tsx
MarkdownViewer.tsx
Result
before(page router)(no pre-render for source)
after(app router)(pre-render for source)
You can check in here
Question
Guess
The reason is maybe difference from
dynamic import
and'use client'
. When usingdynamic import
there is no element for rendering and redering start in browser. However,'use client'
is not meaning perfect client side rendering, It pre-render elements which next.js can pre-render. (docs)But I don't know how next.js decide the boundary of pre-render. If anyone knows the answer about this question, please talk about that! Thanks.
The text was updated successfully, but these errors were encountered: