From 1c7c0293aaaaee2e608592cb98f7f145c2e3d2de Mon Sep 17 00:00:00 2001 From: brgndy Date: Sun, 26 May 2024 21:20:11 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20=EB=A6=AC=EC=95=A1=ED=8A=B8=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=EC=9D=98=20?= =?UTF-8?q?=ED=8F=AC=EB=A0=8C=EC=8B=9D.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nsics Of React Server Components (RSCs).md | 652 ++++++++++++++++++ 1 file changed, 652 insertions(+) create mode 100644 May/article/The Forensics Of React Server Components (RSCs).md diff --git a/May/article/The Forensics Of React Server Components (RSCs).md b/May/article/The Forensics Of React Server Components (RSCs).md new file mode 100644 index 0000000..91eb625 --- /dev/null +++ b/May/article/The Forensics Of React Server Components (RSCs).md @@ -0,0 +1,652 @@ +## ๐Ÿ”— [The Forensics Of React Server Components (RSCs)](https://www.smashingmagazine.com/2024/05/forensics-react-server-components/?utm_source=newsletter.reactdigest.net&utm_medium=newsletter&utm_campaign=the-forensics-of-react-server-components) + +### ๐Ÿ—“๏ธ ๋ฒˆ์—ญ ๋‚ ์งœ: 2024.05.26 + +### ๐Ÿงš ๋ฒˆ์—ญํ•œ ํฌ๋ฃจ: ๋ฒ„๊ฑด๋””(์ „ํƒœํ—Œ) + +--- + +# ๋ฆฌ์•กํŠธ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์˜ ํฌ๋ Œ์‹ + +์„œ๋ฒ„์˜ ์ž‘์—… ๋ถ€๋‹ด์„ ๋œ์–ด์ค€๋‹ค๋Š” ์ ์—์„œ ํด๋ผ์ด์–ธํŠธ ์ธก ๋ Œ๋”๋ง์„ ์ข‹์•„ํ•˜์ง€๋งŒ, ๋นˆ HTML ํŽ˜์ด์ง€๋ฅผ ์ œ๊ณตํ•˜๋ฉด ์ดˆ๊ธฐ ํŽ˜์ด์ง€ ๋กœ๋“œ ์‹œ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์— ๋ถ€๋‹ด์„ ์ฃผ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค. + +์„œ๋ฒ„ ์ธก ๋ Œ๋”๋ง์€ ๋น ๋ฅธ CDN์—์„œ ์ •์  ์ž์‚ฐ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ข‹์•„ํ•˜์ง€๋งŒ ๋™์  ์ฝ˜ํ…์ธ ๊ฐ€ ํฌํ•จ๋œ ๋Œ€๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +React Server Components(RSCs)๋Š” ์ด๋Ÿฌํ•œ ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์˜ ์žฅ์ ์„ ๊ฒฐํ•ฉํ•œ ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค. + +Lazar Nikolov์€ RSCs๊ฐ€ ์–ด๋–ป๊ฒŒ ํ˜„์žฌ์˜ ๊ธฐ์ˆ ์  ์œ„์น˜์— ๋„๋‹ฌํ–ˆ๋Š”์ง€, ๊ทธ๋ฆฌ๊ณ  ๋ฆฌ์•กํŠธ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํŽ˜์ด์ง€ ๋กœ๋“œ ํƒ€์ž„๋ผ์ธ์— ๋ฏธ์น˜๋Š” ์˜ํ–ฅ์„ ์‹ฌ๋„ ์žˆ๊ฒŒ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค. + +์ด ๊ธฐ์‚ฌ์—์„œ๋Š” React ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(RSCs)์— ๋Œ€ํ•ด ๊นŠ์ด ์žˆ๊ฒŒ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +RSCs๋Š” React ์ƒํƒœ๊ณ„์˜ ์ตœ์‹  ํ˜์‹ ์œผ๋กœ, ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง๊ณผ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง์„ ๋ชจ๋‘ ํ™œ์šฉํ•˜๋ฉฐ [HTML ์ŠคํŠธ๋ฆฌ๋ฐ](https://en.wikipedia.org/wiki/Chunked_transfer_encoding)์„ ํ†ตํ•ด ๊ฐ€๋Šฅํ•œ ํ•œ ๋น ๋ฅด๊ฒŒ ์ฝ˜ํ…์ธ ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. + +์šฐ๋ฆฌ๋Š” React ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(RSCs)์— ๋Œ€ํ•ด ๊นŠ์ด ์žˆ๊ฒŒ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ์ž์„ธํžˆ ํƒ๊ตฌํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +์ด๋ฅผ ํ†ตํ•ด RSCs๊ฐ€ React ์ƒํƒœ๊ณ„์—์„œ ์–ด๋–ค ์—ญํ• ์„ ํ•˜๋Š”์ง€, ์ปดํฌ๋„ŒํŠธ์˜ ๋ Œ๋”๋ง ๋ผ์ดํ”„์‚ฌ์ดํด์— ๋Œ€ํ•ด ์–ผ๋งˆ๋‚˜ ๋งŽ์€ ์ œ์–ด๋ฅผ ์ œ๊ณตํ•˜๋Š”์ง€, ๊ทธ๋ฆฌ๊ณ  RSCs๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ํŽ˜์ด์ง€ ๋กœ๋“œ๊ฐ€ ์–ด๋–ป๊ฒŒ ์ด๋ฃจ์–ด์ง€๋Š”์ง€๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +๊ทธ๋Ÿฌ๋‚˜ ์ด๋Ÿฌํ•œ ๋‚ด์šฉ์„ ๊นŠ์ด ํƒ๊ตฌํ•˜๊ธฐ ์ „์—, ์™œ ์šฐ๋ฆฌ๊ฐ€ React ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(RSCs)๊ฐ€ ํ•„์š”ํ•œ์ง€์— ๋Œ€ํ•œ ๋ฐฐ๊ฒฝ์„ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด ์ง€๊ธˆ๊นŒ์ง€ React๊ฐ€ ์›น์‚ฌ์ดํŠธ๋ฅผ ๋ Œ๋”๋งํ•ด์˜จ ๋ฐฉ์‹์„ ๋˜๋Œ์•„๋ณด๋Š” ๊ฒƒ์ด ๋จผ์ €๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. + +# ์ดˆ๊ธฐ ์‹œ๋Œ€: React ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง + +์ดˆ๊ธฐ React ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ํด๋ผ์ด์–ธํŠธ ์ธก, ์ฆ‰ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋ Œ๋”๋ง๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +๊ฐœ๋ฐœ์ž๋กœ์„œ ์šฐ๋ฆฌ๋Š” JavaScript ํด๋ž˜์Šค๋ฅผ ์ปดํฌ๋„ŒํŠธ๋กœ ์‚ฌ์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ž‘์„ฑํ•˜๊ณ , Webpack๊ณผ ๊ฐ™์€ ๋ฒˆ๋“ค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ์ฝ”๋“œ๋ฅผ ์ž˜ ์ปดํŒŒ์ผํ•˜๊ณ  ํŠธ๋ฆฌ ์‰์ดํ‚นํ•˜์—ฌ ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•  ์ค€๋น„๊ฐ€ ๋œ ์ฝ”๋“œ ๋ญ‰์น˜๋กœ ํŒจํ‚ค์ง•ํ–ˆ์Šต๋‹ˆ๋‹ค. + +์„œ๋ฒ„์—์„œ ๋ฐ˜ํ™˜๋œ HTML์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช‡ ๊ฐ€์ง€ ์š”์†Œ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค: + +- ``์— ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๊ฐ€ ํฌํ•จ๋œ HTML ๋ฌธ์„œ์™€, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ DOM์— ์ฃผ์ž…ํ•˜๊ธฐ ์œ„ํ•œ ํ›…์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ``์˜ ๋นˆ `
` + +- React์˜ ํ•ต์‹ฌ ์ฝ”๋“œ์™€ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์‹ค์ œ ์ฝ”๋“œ๊ฐ€ ํฌํ•จ๋œ JavaScript ๋ฆฌ์†Œ์Šค. + ์ด ๋ฆฌ์†Œ์Šค๋“ค์€ ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋นˆ `
` ๋‚ด๋ถ€์— ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ฑ„์›Œ ๋„ฃ์—ˆ์Šต๋‹ˆ๋‹ค. + +![](https://files.smashing.media/articles/forensics-react-server-components/1-client-side-rendering-process.jpg) + +์ด ๊ณผ์ •์—์„œ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ JavaScript๊ฐ€ ๋ชจ๋“  ์ž‘์—…์„ ์™„๋ฃŒํ•œ ํ›„์—์•ผ ๋น„๋กœ์†Œ ์™„์ „ํžˆ ์ƒํ˜ธ์ž‘์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. + +**์—ฌ๊ธฐ์„œ ๊ฐœ๋ฐœ์ž ๊ฒฝํ—˜(DX)์ด ๊ฐœ์„ ๋˜์ง€๋งŒ ๋™์‹œ์— ์‚ฌ์šฉ์ž ๊ฒฝํ—˜(UX)์ด ์•ˆ์ข‹์•„์ง€๋Š” ๋Š๋‚Œ์ด ๋“ค์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.** + +์‚ฌ์‹ค, React์˜ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง(CSR)์—๋Š” ์žฅ๋‹จ์ ์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. + +๊ธ์ •์ ์ธ ์ธก๋ฉด์„ ์‚ดํŽด๋ณด๋ฉด, ๋ฐ˜์‘ํ˜• ์ปดํฌ๋„ŒํŠธ ๋•๋ถ„์— ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ ์—†์ด ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ์— ๋”ฐ๋ผ ์—…๋ฐ์ดํŠธ๋˜๋ฏ€๋กœ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋ถ€๋“œ๋Ÿฝ๊ณ  ๋น ๋ฅธ ์ „ํ™˜์„ ์ œ๊ณตํ•˜์—ฌ ํŽ˜์ด์ง€ ๋กœ๋“œ ์‹œ๊ฐ„์„ ๋‹จ์ถ•์‹œ์ผฐ์Šต๋‹ˆ๋‹ค + +CSR์€ ์„œ๋ฒ„ ๋ถ€ํ•˜๋ฅผ ์ค„์ด๊ณ , CDN์„ ํ†ตํ•ด ์ž์‚ฐ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์–ด, ์‚ฌ์šฉ์ž์˜ ์ง€๋ฆฌ์ ์œผ๋กœ ๊ฐ€๊นŒ์šด ์„œ๋ฒ„ ์œ„์น˜์—์„œ ์ฝ˜ํ…์ธ ๋ฅผ ์ œ๊ณตํ•จ์œผ๋กœ์จ ํŽ˜์ด์ง€ ๋กœ๋“œ๋ฅผ ๋”์šฑ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +CSR์—๋Š” ๊ทธ๋ฆฌ ์ข‹์ง€ ์•Š์€ ๊ฒฐ๊ณผ๋„ ๋”ฐ๋ฅด๋Š”๋ฐ, ํŠนํžˆ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋…๋ฆฝ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์–ด [์›Œํ„ฐํด ๋„คํŠธ์›Œํฌ ์š”์ฒญ](https://blog.sentry.io/fetch-waterfall-in-react/)์ด ๋ฐœ์ƒํ•ด ์†๋„๊ฐ€ ํฌ๊ฒŒ ์ €ํ•˜๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์ด๋Š” UX ์ธก๋ฉด์—์„œ ์‚ฌ์†Œํ•œ ๋ถˆํŽธ์ฒ˜๋Ÿผ ๋“ค๋ฆด ์ˆ˜ ์žˆ์ง€๋งŒ, ์‹ค์ œ๋กœ๋Š” ํฐ ํ”ผํ•ด๋ฅผ ์ดˆ๋ž˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +Eric Bailey์˜ โ€œ[Modern Health, frameworks, performance, and harm](https://ericwbailey.design/published/modern-health-frameworks-performance-and-harm/)โ€ ๊ธ€์€ CSR ์ž‘์—…์— ๋Œ€ํ•ด ๊ฒฝ๊ณ ๋ฅผ ์ฃผ๋Š” ์ด์•ผ๊ธฐ์ž…๋‹ˆ๋‹ค. + +๋‹ค๋ฅธ CSR์˜ ๋ถ€์ •์ ์ธ ๊ฒฐ๊ณผ๋Š” ๊ทธ๋ฆฌ ์‹ฌ๊ฐํ•˜์ง€๋Š” ์•Š์ง€๋งŒ ์—ฌ์ „ํžˆ ํ”ผํ•ด๋ฅผ ์ดˆ๋ž˜ํ•ฉ๋‹ˆ๋‹ค. + +์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ์™€ ๋นˆ `
`๋งŒ ํฌํ•จ๋œ HTML ๋ฌธ์„œ๋Š” ์™„์ „ํžˆ ๋ Œ๋”๋ง๋œ ๊ฒฝํ—˜์„ ์ œ๊ณตํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค. + +๊ทธ๋ฆฌํ•˜์—ฌ ๊ฒ€์ƒ‰ ์—”์ง„ ํฌ๋กค๋Ÿฌ๊ฐ€ ์ด๋ฅผ ํŒ๋…ํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ–ˆ์Šต๋‹ˆ๋‹ค. + +์˜ค๋Š˜๋‚ ์—๋Š” ์ด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ์ง€๋งŒ, ๋‹น์‹œ์—๋Š” ๊ฒ€์ƒ‰ ์—”์ง„ ํŠธ๋ž˜ํ”ฝ์— ์˜์กดํ•ด ์ˆ˜์ต์„ ์ฐฝ์ถœํ•˜๋Š” ํšŒ์‚ฌ ์‚ฌ์ดํŠธ์— SEO(๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™”) ์˜ํ–ฅ์„ ๋ฏธ์ณ ํฐ ์ œ์•ฝ์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +# ๋ณ€ํ™”: ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง(SSR) + +๋ณ€ํ™”๊ฐ€ ํ•„์š”ํ–ˆ์Šต๋‹ˆ๋‹ค. + +CSR์€ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ๋น ๋ฅด๊ณ  ์ƒํ˜ธ์ž‘์šฉ์ด ๊ฐ€๋Šฅํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š” ๊ฐ•๋ ฅํ•œ ์ƒˆ๋กœ์šด ์ ‘๊ทผ ๋ฐฉ์‹์„ ์ œ๊ณตํ–ˆ์ง€๋งŒ, ์‚ฌ์šฉ์ž๋“ค์€ ๋นˆ ํ™”๋ฉด๊ณผ ๋กœ๋”ฉ ํ‘œ์‹œ๋ฅผ ๋งˆ์ฃผํ•˜๋Š” ์ƒํ™ฉ์ด ๋งŽ์•˜์Šต๋‹ˆ๋‹ค. + +์ด์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ…์€ ๋ Œ๋”๋ง์„ ํด๋ผ์ด์–ธํŠธ์—์„œ ์„œ๋ฒ„๋กœ ์ด๋™์‹œํ‚ค๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค. + +๊ณผ๊ฑฐ์˜ ๋ฐฉ์‹์œผ๋กœ ๋Œ์•„๊ฐ€์„œ ๊ฐœ์„ ํ•ด์•ผ ํ–ˆ๋‹ค๋Š” ๊ฒƒ์ด ํฅ๋ฏธ๋กญ๊ฒŒ ๋“ค๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +๊ทธ๋ž˜์„œ React๋Š” ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง(SSR) ๊ธฐ๋Šฅ์„ ๊ฐ–์ถ”๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +[ํ•œ๋•Œ SSR์€ React ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ํฐ ํ™”์ œ๊ฐ€ ๋˜์–ด ์ฃผ๋ชฉ๋ฐ›๊ธฐ๋„ ํ–ˆ์Šต๋‹ˆ๋‹ค.](https://sentry.io/resources/moving-to-server-side-rendering/) + +SSR๋กœ์˜ ์ „ํ™˜์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์— ์ค‘์š”ํ•œ ๋ณ€ํ™”๋ฅผ ๊ฐ€์ ธ์™”์œผ๋ฉฐ, ํŠนํžˆ React์˜ ๋™์ž‘ ๋ฐฉ์‹๊ณผ ์ฝ˜ํ…์ธ ๊ฐ€ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์•„๋‹Œ ์„œ๋ฒ„๋ฅผ ํ†ตํ•ด ์ „๋‹ฌ๋˜๋Š” ๋ฐฉ์‹์— ํฐ ์˜ํ–ฅ์„ ๋ฏธ์ณค์Šต๋‹ˆ๋‹ค. + +![](https://files.smashing.media/articles/forensics-react-server-components/2-diagram-server-side-rendering-process.jpg) + +# CSR์˜ ํ•œ๊ณ„ ํ•ด๊ฒฐ + +SSR์„ ์‚ฌ์šฉํ•˜๋ฉด ๋นˆ HTML ๋ฌธ์„œ๋ฅผ ๋ณด๋‚ด๋Š” ๋Œ€์‹ , ์ดˆ๊ธฐ HTML์„ ์„œ๋ฒ„์—์„œ ๋ Œ๋”๋งํ•˜์—ฌ ๋ธŒ๋ผ์šฐ์ €๋กœ ์ „์†กํ–ˆ์Šต๋‹ˆ๋‹ค. + +์ด๋ฅผ ํ†ตํ•ด ๋ธŒ๋ผ์šฐ์ €๋Š” ๋กœ๋”ฉ ํ‘œ์‹œ๊ธฐ๋ฅผ ํ‘œ์‹œํ•˜์ง€ ์•Š๊ณ  ์ฆ‰์‹œ ์ฝ˜ํ…์ธ ๋ฅผ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. + +์ด ๋ฐฉ์‹์€ Web Vitals์—์„œ ์ค‘์š”ํ•œ ์„ฑ๋Šฅ ์ง€ํ‘œ์ธ [First Contentful Paint(FCP)๋ฅผ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค.](https://docs.sentry.io/product/performance/web-vitals/web-vitals-concepts/#first-paint-fp) + +์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง(SSR)์€ CSR๊ณผ ํ•จ๊ป˜ ๋ฐœ์ƒํ–ˆ๋˜ SEO ๋ฌธ์ œ๋„ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค. + +ํฌ๋กค๋Ÿฌ๊ฐ€ ์›น์‚ฌ์ดํŠธ์˜ ์ฝ˜ํ…์ธ ๋ฅผ ์ง์ ‘ ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์ฆ‰์‹œ ์ธ๋ฑ์‹ฑํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. + +์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ํŽ˜์นญ๋„ ์„œ๋ฒ„์—์„œ ์ด๋ฃจ์–ด์ง€๋Š”๋ฐ, ์ด๋Š” ๋ฐ์ดํ„ฐ ์†Œ์Šค์™€ ๊ฐ€๊นŒ์›Œ์„œ ์ ์ ˆํžˆ ์ˆ˜ํ–‰๋˜๋ฉด [์›Œํ„ฐํด ํŽ˜์นญ ๋ฌธ์ œ๋ฅผ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ](https://blog.sentry.io/fetch-waterfall-in-react/#fetch-data-on-server-to-avoid-a-fetch-waterfall)์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +# - Hydration + +SSR์—๋Š” ์ž์ฒด์ ์ธ ๋ณต์žก์„ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +์„œ๋ฒ„์—์„œ ๋ฐ›์€ ์ •์  HTML์„ React๊ฐ€ ์ƒํ˜ธ์ž‘์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ๋Š” "Hydration"์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. + +Hydration์€ React๊ฐ€ ์ดˆ๊ธฐ HTML์˜ DOM์— ์žˆ๋Š” ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ๊ฐ€์ƒ DOM(Virtual DOM)์„ ์žฌ๊ตฌ์„ฑํ•˜๋Š” ๊ณผ์ •์ž…๋‹ˆ๋‹ค. + +์ฐธ๊ณ : React๋Š” ์‹ค์ œ DOM ๋Œ€์‹  [๊ฐ€์ƒ DOM(Virtual DOM)](https://legacy.reactjs.org/docs/faq-internals.html)์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. + +์ด๋Š” ์‹ค์ œ DOM๋ณด๋‹ค ๊ฐ€์ƒ DOM์—์„œ ์—…๋ฐ์ดํŠธ๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๊ฒƒ์ด ๋” ๋น ๋ฅด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. + +React๋Š” UI๋ฅผ ์—…๋ฐ์ดํŠธํ•  ๋•Œ ๊ฐ€์ƒ DOM์—์„œ ์ฐจ์ด(diff)๋ฅผ ๊ณ„์‚ฐํ•˜๊ณ , ์‹ค์ œ DOM์„ ๊ฐ€์ƒ DOM๊ณผ ๋™๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค. + +ํ˜„์žฌ ์šฐ๋ฆฌ๋Š” ๋‘ ๊ฐ€์ง€ ์œ ํ˜•์˜ React๋ฅผ ๊ฐ–๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค: + +1. ์„œ๋ฒ„ ์‚ฌ์ด๋“œ React: ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ์—์„œ ์ •์  HTML์„ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋Š” ๋ฒ„์ „. + +2. ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ React: ํŽ˜์ด์ง€๋ฅผ ์ƒํ˜ธ์ž‘์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ๋ฒ„์ „. + +์šฐ๋ฆฌ๋Š” ์—ฌ์ „ํžˆ React์™€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ๋ฅผ ๋ธŒ๋ผ์šฐ์ €์— ์ „์†กํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. + +์™œ๋ƒํ•˜๋ฉด ์ดˆ๊ธฐ HTML์„ ์ˆ˜ํ™”(hydrate)ํ•˜๋ ค๋ฉด ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ๋„ ์„œ๋ฒ„์—์„œ ์‚ฌ์šฉํ•œ ๋™์ผํ•œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. + +hydration ๊ณผ์ •์—์„œ React๋Š” [์žฌ์กฐ์ •(reconciliation)](https://css-tricks.com/how-react-reconciliation-works/)์ด๋ผ๋Š” ๊ณผ์ •์„ ์ˆ˜ํ–‰ํ•˜๋Š”๋ฐ, ์ด๋Š” ์„œ๋ฒ„์—์„œ ๋ Œ๋”๋ง๋œ DOM๊ณผ ํด๋ผ์ด์–ธํŠธ์—์„œ ๋ Œ๋”๋ง๋œ DOM์„ ๋น„๊ตํ•˜์—ฌ ๋‘ DOM ๊ฐ„์˜ ์ฐจ์ด์ ์„ ์‹๋ณ„ํ•˜๋ ค๊ณ  ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค. + +๋งŒ์•ฝ ๋‘ DOM ๊ฐ„์— ์ฐจ์ด์ ์ด ์žˆ๋‹ค๋ฉด, React๋Š” ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ๋ฅผ ๋‹ค์‹œ hydrationํ•˜๊ณ , ์„œ๋ฒ„์—์„œ ๋ Œ๋”๋ง๋œ ๊ตฌ์กฐ์™€ ์ผ์น˜ํ•˜๋„๋ก ์ปดํฌ๋„ŒํŠธ ๊ณ„์ธต์„ ์—…๋ฐ์ดํŠธํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. + +๋งŒ์•ฝ ํ•ด๊ฒฐํ•  ์ˆ˜ ์—†๋Š” ๋ถˆ์ผ์น˜๊ฐ€ ์—ฌ์ „ํžˆ ์กด์žฌํ•œ๋‹ค๋ฉด, React๋Š” ๋ฌธ์ œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค. + +์ด ๋ฌธ์ œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ `hydration error`๋กœ ์•Œ๋ ค์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. + +# SSR์˜ ๋‹จ์  + +SSR์€ CSR์˜ ํ•œ๊ณ„๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋งŒ๋Šฅ ์†”๋ฃจ์…˜์ด ์•„๋‹™๋‹ˆ๋‹ค. + +SSR ์ž์ฒด์—๋„ ๋‹จ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +์ดˆ๊ธฐ HTML ๋ Œ๋”๋ง๊ณผ ๋ฐ์ดํ„ฐ ํŽ˜์นญ์„ ์„œ๋ฒ„๋กœ ์˜ฎ๊ฒผ๊ธฐ ๋•Œ๋ฌธ์—, ์ด์ œ ์„œ๋ฒ„๋Š” ๋ชจ๋“  ๊ฒƒ์„ ํด๋ผ์ด์–ธํŠธ์—์„œ ๋กœ๋“œํ•  ๋•Œ๋ณด๋‹ค ํ›จ์”ฌ ๋” ํฐ ๋ถ€ํ•˜๋ฅผ ๊ฒฝํ—˜ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. + +SSR์ด ์ผ๋ฐ˜์ ์œผ๋กœ First Contentful Paint(FCP) ์„ฑ๋Šฅ ์ง€ํ‘œ๋ฅผ ๊ฐœ์„ ํ•œ๋‹ค๊ณ  ์–ธ๊ธ‰ํ•œ ๊ฒƒ์„ ๊ธฐ์–ตํ•˜์‹œ๋‚˜์š”? + +์ด๋Š” ์‚ฌ์‹ค์ด์ง€๋งŒ, SSR๋กœ ์ธํ•ด [Time to First Byte(TTFB)](https://docs.sentry.io/product/performance/web-vitals/web-vitals-concepts/#first-contentful-paint-fcp) ์„ฑ๋Šฅ ์ง€ํ‘œ๋Š” ๋ถ€์ •์ ์ธ ์˜ํ–ฅ์„ ๋ฐ›์Šต๋‹ˆ๋‹ค. + +๋ธŒ๋ผ์šฐ์ €๋Š” ์„œ๋ฒ„๊ฐ€ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ํŽ˜์นญํ•˜๊ณ , ์ดˆ๊ธฐ HTML์„ ์ƒ์„ฑํ•˜์—ฌ ์ฒซ ๋ฒˆ์งธ ๋ฐ”์ดํŠธ๋ฅผ ์ „์†กํ•  ๋•Œ๊นŒ์ง€ ์‹ค์ œ๋กœ ๊ธฐ๋‹ค๋ ค์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +TTFB ์ž์ฒด๋Š” ํ•ต์‹ฌ ์›น ๋ฐ”์ดํƒˆ(Core Web Vitals) ์ง€ํ‘œ๋Š” ์•„๋‹ˆ์ง€๋งŒ, ๋‹ค๋ฅธ ์ง€ํ‘œ์— ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค. + +TTFB๊ฐ€ ๋ถ€์ •์ ์ด๋ฉด Core Web Vitals ์ง€ํ‘œ๋„ ๋ถ€์ •์ ์ธ ์˜ํ–ฅ์„ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. + +SSR์˜ ๋˜ ๋‹ค๋ฅธ ๋‹จ์ ์€ ํด๋ผ์ด์–ธํŠธ ์ธก React๊ฐ€ hydration๋ฅผ ์™„๋ฃŒํ•˜๊ธฐ ์ „๊นŒ์ง€ ์ „์ฒด ํŽ˜์ด์ง€๊ฐ€ ์‘๋‹ตํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. + +์ƒํ˜ธ์ž‘์šฉ ์š”์†Œ๋Š” React๊ฐ€ ์ด๋ฅผ hydrationํ•˜๊ธฐ ์ „๊นŒ์ง€, ์ฆ‰ React๊ฐ€ ์˜๋„๋œ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์—ฐ๊ฒฐํ•˜๊ธฐ ์ „๊นŒ์ง€ ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ์— ์‘๋‹ตํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. + +hydration ๊ณผ์ •์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋น ๋ฅด์ง€๋งŒ, ์ธํ„ฐ๋„ท ์—ฐ๊ฒฐ ์†๋„์™€ ์‚ฌ์šฉ ์ค‘์ธ ์žฅ์น˜์˜ ํ•˜๋“œ์›จ์–ด ์„ฑ๋Šฅ์— ๋”ฐ๋ผ ๋ Œ๋”๋ง ์†๋„๊ฐ€ ๋ˆˆ์— ๋„๊ฒŒ ๋Š๋ ค์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +# ํ˜„์žฌ: ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์ ‘๊ทผ๋ฒ• + +์ง€๊ธˆ๊นŒ์ง€ ์šฐ๋ฆฌ๋Š” React ๋ Œ๋”๋ง์˜ ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์ธ CSR(ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง)๊ณผ SSR(์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง)์— ๋Œ€ํ•ด ๋‹ค๋ฃจ์—ˆ์Šต๋‹ˆ๋‹ค. + +๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์€ ์„œ๋กœ๋ฅผ ๊ฐœ์„ ํ•˜๋ ค๋Š” ์‹œ๋„๋กœ ๋“ฑ์žฅํ–ˆ์ง€๋งŒ, ์ด์ œ๋Š” CSR๊ณผ SSR์˜ ๋‹จ์ ์„ ์ค„์ด๊ณ  ์žฅ์ ์„ ๋ชจ๋‘ ์‚ด๋ฆฌ๊ธฐ ์œ„ํ•ด SSR์ด ์„ธ ๊ฐ€์ง€ ์ถ”๊ฐ€์ ์ธ React ๋ฐฉ์‹์œผ๋กœ ๋ฐœ์ „ํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +์ด์ œ ์ฒซ ๋ฒˆ์งธ์™€ ๋‘ ๋ฒˆ์งธ ๋ฐฉ์‹์ธ **์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ(Static Site Generation ์ฆ‰, SSG)**๊ณผ **์ฆ๋ถ„ ์ •์  ์žฌ์ƒ์„ฑ(Incremental Static Regeneration ์ฆ‰, ISR)**์— ๋Œ€ํ•ด ์‚ดํŽด๋ณธ ํ›„, React ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ผ๋Š” ์„ธ ๋ฒˆ์งธ ๋ฐฉ์‹์— ๋Œ€ํ•ด ์ „์ฒด์ ์œผ๋กœ ๋…ผ์˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +## ์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ (SSG) + +๋งค ์š”์ฒญ๋งˆ๋‹ค ๋™์ผํ•œ HTML ์ฝ”๋“œ๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•˜๋Š” ๋Œ€์‹ , ์šฐ๋ฆฌ๋Š” SSG(์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ)๋ฅผ ๊ณ ์•ˆํ•ด๋ƒˆ์Šต๋‹ˆ๋‹ค. + +์ด React ๋ฐฉ์‹์€ ๋นŒ๋“œ ์‹œ์ ์— ์ „์ฒด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ปดํŒŒ์ผํ•˜๊ณ  ๋นŒ๋“œํ•˜์—ฌ ์ •์ (์ˆœ์ˆ˜ HTML๊ณผ CSS) ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด๋Ÿฌํ•œ ํŒŒ์ผ๋“ค์€ ๋น ๋ฅธ CDN(Content Delivery Network)์— ํ˜ธ์ŠคํŒ…๋ฉ๋‹ˆ๋‹ค. + +์ด ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ๋ Œ๋”๋ง ๋ฐฉ์‹์€ ์ฝ˜ํ…์ธ  ๋ณ€ํ™”๊ฐ€ ์ ์€ ๋งˆ์ผ€ํŒ… ์‚ฌ์ดํŠธ๋‚˜ ๊ฐœ์ธ ๋ธ”๋กœ๊ทธ์— ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค. + +์ด๋Š” ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ์œผ๋กœ ์ธํ•ด ์ฝ˜ํ…์ธ ๊ฐ€ ์ž์ฃผ ๋ณ€๊ฒฝ๋˜๋Š” ๋Œ€๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ, ์˜ˆ๋ฅผ ๋“ค์–ด ์ „์ž์ƒ๊ฑฐ๋ž˜ ์‚ฌ์ดํŠธ์™€๋Š” ๋งž์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +SSG๋Š” ์„œ๋ฒ„์˜ ๋ถ€๋‹ด์„ ์ค„์ด๋Š” ๋™์‹œ์— TTFB(Time To First Byte)์™€ ๊ด€๋ จ๋œ ์„ฑ๋Šฅ ์ง€ํ‘œ๋ฅผ ๊ฐœ์„ ํ•ฉ๋‹ˆ๋‹ค. + +์™œ๋ƒํ•˜๋ฉด ์„œ๋ฒ„๊ฐ€ ํŽ˜์ด์ง€๋ฅผ ๋‹ค์‹œ ๋ Œ๋”๋งํ•˜๊ธฐ ์œ„ํ•ด ๋ฌด๊ฒ๊ณ  ๋น„์šฉ์ด ๋งŽ์ด ๋“œ๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ํ•„์š”๊ฐ€ ์—†์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. + +## ์ฆ๋ถ„ ์ •์  ์žฌ์ƒ์„ฑ (ISR) + +SSG(์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ)์˜ ํ•œ ๊ฐ€์ง€ ๋‹จ์ ์€ ์ฝ˜ํ…์ธ  ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•  ๋•Œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ชจ๋“  ์ฝ”๋“œ๋ฅผ ๋‹ค์‹œ ๋นŒ๋“œํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. + +์ฝ˜ํ…์ธ ๋Š” ๊ณ ์ •๋˜์–ด ์žˆ์–ด(์ •์ ์ด๋ฏ€๋กœ) ๊ทธ ์ผ๋ถ€๋งŒ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๊ณ  ์ „์ฒด๋ฅผ ๋‹ค์‹œ ๋นŒ๋“œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Next.js ํŒ€์€ ๋‘ ๋ฒˆ์งธ ํ•˜์ด๋ธŒ๋ฆฌ๋“œ React ๋ฐฉ์‹์„ ๋งŒ๋“ค์–ด๋ƒˆ์Šต๋‹ˆ๋‹ค. + +**์ฆ๋ถ„ ์ •์  ์žฌ์ƒ์„ฑ(ISR, Incremental Static Regeneration)** + +ISR์€ ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ ์ „์ฒด๋ฅผ ๋‹ค์‹œ ๋นŒ๋“œํ•˜๋Š” ๋Œ€์‹  ํ•„์š”ํ•œ ๋ถ€๋ถ„๋งŒ ์žฌ์ƒ์„ฑํ•˜๋Š” ์ ‘๊ทผ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. + +๋นŒ๋“œ ์‹œ์ ์— ํŽ˜์ด์ง€์˜ "์ดˆ๊ธฐ ๋ฒ„์ „"์„ ์ •์ ์œผ๋กœ ์ƒ์„ฑํ•˜์ง€๋งŒ, ์‚ฌ์šฉ์ž๊ฐ€ ๋ฐฉ๋ฌธํ•œ ํ›„ ๋ฐ์ดํ„ฐ๊ฐ€ ์˜ค๋ž˜๋œ ํŽ˜์ด์ง€๋Š” ์„œ๋ฒ„ ์š”์ฒญ์ด ๋ฐ์ดํ„ฐ ๊ฒ€์‚ฌ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜์—ฌ ๋‹ค์‹œ ๋นŒ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +๊ทธ ์‹œ์ ๋ถ€ํ„ฐ ์„œ๋ฒ„๋Š” ํ•„์š”ํ•  ๋•Œ๋งˆ๋‹ค ์ƒˆ ๋ฒ„์ „์˜ ํŽ˜์ด์ง€๋ฅผ ์ ์ง„์ ์œผ๋กœ ์ •์ ์œผ๋กœ ์ œ๊ณตํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ISR์€ SSG์™€ ์ „ํ†ต์ ์ธ SSR ์‚ฌ์ด์— ์œ„์น˜ํ•œ ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์ ‘๊ทผ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. + +ํ•˜์ง€๋งŒ ISR์€ "์˜ค๋ž˜๋œ ์ฝ˜ํ…์ธ " ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค. + +์‚ฌ์šฉ์ž๊ฐ€ ํŽ˜์ด์ง€๋ฅผ ๋ฐฉ๋ฌธํ•  ๋•Œ ํ•ด๋‹น ํŽ˜์ด์ง€๊ฐ€ ์•„์ง ์ƒ์„ฑ ์ค‘์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +SSG์™€ ๋‹ฌ๋ฆฌ ISR์€ ์‚ฌ์šฉ์ž์˜ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์„œ๋ฒ„ ์š”์ฒญ์„ ํ•  ๋•Œ ๊ฐœ๋ณ„ ํŽ˜์ด์ง€๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์‹ค์ œ ์„œ๋ฒ„๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. + +์ด๋Š” ISR ๊ธฐ๋ฐ˜ ์•ฑ์„ CDN์— ๋ฐฐํฌํ•˜์—ฌ ์ตœ์ ํ™”๋œ ์ž๋ฃŒ๋“ค์„ ์ „๋‹ฌํ•˜๋Š” ๋Šฅ๋ ฅ์„ ์žƒ๊ฒŒ ๋จ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. + +## - ๋ฏธ๋ž˜: ๋ฆฌ์•กํŠธ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ + +์ง€๊ธˆ๊นŒ์ง€ ์šฐ๋ฆฌ๋Š” CSR(ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง), SSR(์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง), SSG(์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ), ISR(์ฆ๋ถ„ ์ •์  ์žฌ์ƒ์„ฑ) ์ ‘๊ทผ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ด์™”์Šต๋‹ˆ๋‹ค. + +์ด๋“ค์€ ๋ชจ๋‘ ์–ด๋Š ์ •๋„์˜ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„๋ฅผ ๊ฐ€์ง€๋ฉฐ, ์„ฑ๋Šฅ, ๊ฐœ๋ฐœ ๋ณต์žก๋„, ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์— ๋ถ€์ •์ ์ธ ์˜ํ–ฅ์„ ๋ฏธ์น  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์ƒˆ๋กญ๊ฒŒ ๋„์ž…๋œ [React ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(RSC, React Server Components)](https://nextjs.org/docs/app/building-your-application/rendering/server-components)๋Š” ์ด๋Ÿฌํ•œ ๋‹จ์  ๋Œ€๋ถ€๋ถ„์„ ํ•ด๊ฒฐํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. RSC๋Š” ๊ฐ ๊ฐœ๋ณ„ React ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•ด ์ ์ ˆํ•œ ๋ Œ๋”๋ง ์ „๋žต์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค. + +RSC๋Š” ํด๋ผ์ด์–ธํŠธ๋กœ ์ „์†ก๋˜๋Š” JavaScript์˜ ์–‘์„ ํฌ๊ฒŒ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์„œ๋ฒ„์—์„œ ์ •์ ์œผ๋กœ ์ œ๊ณตํ•  ์ปดํฌ๋„ŒํŠธ์™€ ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ๋ Œ๋”๋งํ•  ์ปดํฌ๋„ŒํŠธ๋ฅผ ์„ ํƒ์ ์œผ๋กœ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. + +์ด๋ฅผ ํ†ตํ•ด ํŠน์ • ํ”„๋กœ์ ํŠธ์— ๋งž๋Š” ์ ์ ˆํ•œ ๊ท ํ˜•์„ ์ฐพ๊ธฐ ์œ„ํ•œ ๋” ๋งŽ์€ ์ œ์–ด์™€ ์œ ์—ฐ์„ฑ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. + +> ์•Œ์•„๋‘์–ด์•ผ ํ• ์  +> ์ฐธ๊ณ : RSC์™€ ๊ฐ™์€ ๋” ๋ฐœ์ „๋œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์ฑ„ํƒํ•  ๋•Œ [๋ชจ๋‹ˆํ„ฐ๋ง ์†”๋ฃจ์…˜](https://docs.sentry.io/product/performance/)์€ ๋งค์šฐ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. +> Sentry๋Š” RSC ๊ธฐ๋ฐ˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์‹ค์ œ ์„ฑ๋Šฅ์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ  ์˜ค๋ฅ˜๋ฅผ ์ถ”์ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ•๋ ฅํ•œ ์„ฑ๋Šฅ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ์˜ค๋ฅ˜ ์ถ”์  ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. +> Sentry๋Š” ๋˜ํ•œ ๋ฆด๋ฆฌ์Šค๊ฐ€ ์–ด๋–ป๊ฒŒ ์„ฑ๋Šฅ์„ ๋ฐœํœ˜ํ•˜๊ณ  ์–ผ๋งˆ๋‚˜ ์•ˆ์ •์ ์ธ์ง€์— ๋Œ€ํ•œ ํ†ต์ฐฐ์„ ์ œ๊ณตํ•˜์—ฌ, ๊ธฐ์กด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ RSC๋กœ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•˜๋Š” ๋™์•ˆ ์ค‘์š”ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. +> [Next.js](https://sentry.io/for/nextjs/)์™€ ๊ฐ™์€ RSC ์ง€์› ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ Sentry๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์€ ๋‹จ์ผ ํ„ฐ๋ฏธ๋„ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ๋งŒํผ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. + +๊ทธ๋Ÿฌ๋‚˜ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ผ๋Š” ๊ฒƒ์€ ์ •ํ™•ํžˆ ๋ฌด์—‡์ผ๊นŒ์š” ? + +ํ•œ๋ฒˆ ๋‚ด๋ถ€์ ์œผ๋กœ ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋Š”์ง€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +## - ๋ฆฌ์•กํŠธ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์˜ ๊ตฌ์กฐ + +์ด ์ƒˆ๋กœ์šด ์ ‘๊ทผ๋ฒ•์€ ๋‘ ๊ฐ€์ง€ ์œ ํ˜•์˜ ๋ Œ๋”๋ง ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋„์ž…ํ•ฉ๋‹ˆ๋‹ค. + +๋ฐ”๋กœ **์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(Server Components)**์™€ **ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ(Client Components)**์ž…๋‹ˆ๋‹ค. + +์ด ๋‘ ์ปดํฌ๋„ŒํŠธ์˜ ์ฐจ์ด์ ์€ ๊ธฐ๋Šฅ์ด ์•„๋‹Œ ์‹คํ–‰๋˜๋Š” ์œ„์น˜์™€ ์„ค๊ณ„๋œ ํ™˜๊ฒฝ์ž…๋‹ˆ๋‹ค. + +์ด ๊ธ€์„ ์ž‘์„ฑํ•˜๋Š” ์‹œ์ ์—์„œ RSC๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์œ ์ผํ•œ ๋ฐฉ๋ฒ•์€ React ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ํ†ตํ•ด์„œ์ž…๋‹ˆ๋‹ค. + +ํ˜„์žฌ RSC๋ฅผ ์ง€์›ํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋Š” [Next.js](https://nextjs.org/docs/app/building-your-application/rendering/server-components), [Gatsby](https://www.gatsbyjs.com/docs/conceptual/partial-hydration/), [RedwoodJS](https://redwoodjs.com/blog/rsc-now-in-redwoodjs) ์„ธ ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค. + +![](https://files.smashing.media/articles/forensics-react-server-components/3-wire-diagram-server-client-components.jpg) + +## - ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ + +์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(Server Components)๋Š” ์„œ๋ฒ„์—์„œ ์‹คํ–‰๋˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ์œผ๋ฉฐ, ๊ทธ ์ฝ”๋“œ๋Š” ๋ธŒ๋ผ์šฐ์ €๋กœ ์ „์†ก๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +HTML ์ถœ๋ ฅ๊ณผ ๊ทธ๋“ค์ด ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” props๋งŒ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. + +์ด ์ ‘๊ทผ ๋ฐฉ์‹์€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์„ฑ๋Šฅ์ƒ์˜ ์ด์ ๊ณผ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜ ํ–ฅ์ƒ์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค: + +- **์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(Server Components)๋Š” ํฐ ์˜์กด์„ฑ์„ ์„œ๋ฒ„ ์ธก์— ๋‚จ๊ฒจ๋‘˜ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.** + +ํฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ปดํฌ๋„ŒํŠธ์— ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ์ƒ์ƒํ•ด๋ณด์„ธ์š”. + +์ปดํฌ๋„ŒํŠธ๋ฅผ ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ์‹คํ–‰ํ•˜๋ฉด ์ „์ฒด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋ธŒ๋ผ์šฐ์ €๋กœ ์ „์†กํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +ํ•˜์ง€๋งŒ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ •์  HTML ์ถœ๋ ฅ๋งŒ ๊ฐ€์ ธ๊ฐ€๊ณ  JavaScript๋Š” ๋ธŒ๋ผ์šฐ์ €๋กœ ์ „์†กํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. + +์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” ์ง„์ •์œผ๋กœ ์ •์ ์ด๋ฉฐ, hydration ๋‹จ๊ณ„๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. + +- **์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” ์ฝ”๋“œ ์ƒ์„ฑ์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ ์†Œ์Šค(์˜ˆ: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋˜๋Š” ํŒŒ์ผ ์‹œ์Šคํ…œ)์™€ ํ›จ์”ฌ ๊ฐ€๊น๊ฒŒ ์œ„์น˜ํ•ฉ๋‹ˆ๋‹ค.** + +๋˜ํ•œ ์„œ๋ฒ„์˜ ๊ณ„์‚ฐ ๋Šฅ๋ ฅ์„ ํ™œ์šฉํ•˜์—ฌ ๊ณ„์‚ฐ ์ง‘์•ฝ์ ์ธ ๋ Œ๋”๋ง ์ž‘์—…์„ ๊ฐ€์†ํ™”ํ•˜๊ณ , ์ƒ์„ฑ๋œ ๊ฒฐ๊ณผ๋งŒ ํด๋ผ์ด์–ธํŠธ์— ์ „์†กํ•ฉ๋‹ˆ๋‹ค. + +์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” ํ•œ ๋ฒˆ์— ์ƒ์„ฑ๋˜๋ฏ€๋กœ [์š”์ฒญ ํญํฌ(request waterfalls)์™€ HTTP ์™•๋ณต](https://blog.sentry.io/fetch-waterfall-in-react/#fetch-data-on-server-to-avoid-a-fetch-waterfall)์„ ํ”ผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +- **์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(Server Components)๋Š” ๋ฏผ๊ฐํ•œ ๋ฐ์ดํ„ฐ์™€ ๋กœ์ง์„ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์•ˆ์ „ํ•˜๊ฒŒ ๋ณดํ˜ธํ•ฉ๋‹ˆ๋‹ค.** + +์ด๋Š” ๊ฐœ์ธ ํ† ํฐ๊ณผ API ํ‚ค๊ฐ€ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์•„๋‹Œ ์•ˆ์ „ํ•œ ์„œ๋ฒ„์—์„œ ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. + +- **๋ Œ๋”๋ง ๊ฒฐ๊ณผ๋Š” ์บ์‹œ๋˜์–ด ์ดํ›„ ์š”์ฒญ ๊ฐ„ ๋ฐ ๋‹ค๋ฅธ ์„ธ์…˜ ๊ฐ„์—๋„ ์žฌ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.** + +์ด๋Š” ๋ Œ๋”๋ง ์‹œ๊ฐ„์„ ํฌ๊ฒŒ ์ค„์ด๋ฉฐ, ๊ฐ ์š”์ฒญ๋งˆ๋‹ค ๊ฐ€์ ธ์˜ค๋Š” ์ „์ฒด ๋ฐ์ดํ„ฐ ์–‘๋„ ์ค„์ž…๋‹ˆ๋‹ค. + +์ด ์•„ํ‚คํ…์ฒ˜๋Š” **HTML ์ŠคํŠธ๋ฆฌ๋ฐ**๋„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +์ฆ‰, ์„œ๋ฒ„๋Š” ํŠน์ • ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ HTML ์ƒ์„ฑ์„ ์ง€์—ฐ์‹œํ‚ค๊ณ , ๋Œ€์‹  ์ƒ์„ฑ๋œ HTML์„ ๋ณด๋‚ด๋Š” ๋™์•ˆ ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ์˜ ์ž๋ฆฌ์—๋Š” ๋Œ€์ฒด ์š”์†Œ๋ฅผ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. + +์ŠคํŠธ๋ฆฌ๋ฐ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” [](https://react.dev/reference/react/Suspense) ํƒœ๊ทธ๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ์‹ธ ๋Œ€์ฒด ๊ฐ’์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. + +๊ตฌํ˜„ ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ์ดˆ๊ธฐ์—๋Š” ์ด ๋Œ€์ฒด ์š”์†Œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ, ์ƒˆ๋กœ ์ƒ์„ฑ๋œ ์ฝ˜ํ…์ธ ๊ฐ€ ์ค€๋น„๋˜๋ฉด ์ด๋ฅผ ์ŠคํŠธ๋ฆฌ๋ฐํ•ฉ๋‹ˆ๋‹ค. + +์ŠคํŠธ๋ฆฌ๋ฐ์— ๋Œ€ํ•ด ๋” ์ž์„ธํžˆ ์ด์•ผ๊ธฐํ•˜๊ฒ ์ง€๋งŒ, ๋จผ์ € ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์™€ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋น„๊ตํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +## - ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ + +ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ(Client Components)๋Š” ์šฐ๋ฆฌ๊ฐ€ ์ด๋ฏธ ์ž˜ ์•Œ๊ณ  ์‚ฌ๋ž‘ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ์ž…๋‹ˆ๋‹ค. + +์ด๋“ค์€ ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. + +๋”ฐ๋ผ์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ณ , `localStorage`๋‚˜ ์ง€๋ฆฌ ์œ„์น˜(geolocation)์™€ ๊ฐ™์€ ๋ธŒ๋ผ์šฐ์ € API์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +"ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ"๋ผ๋Š” ์šฉ์–ด๋Š” ์ƒˆ๋กœ์šด ๊ฒƒ์„ ์„ค๋ช…ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค. + +๋‹จ์ง€ ์ด ์šฉ์–ด๋Š” ๊ธฐ์กด์˜ CSR(Client-Side Rendering) ์ปดํฌ๋„ŒํŠธ์™€ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(Server Components)๋ฅผ ๊ตฌ๋ณ„ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. + +ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” ํŒŒ์ผ ์ƒ๋‹จ์— ["use client"](https://react.dev/reference/rsc/use-server) ์ง€์‹œ์–ด๋ฅผ ํฌํ•จํ•˜์—ฌ ์ •์˜๋ฉ๋‹ˆ๋‹ค. + +```tsx +"use client"; +export default function LikeButton() { + const likePost = () => { + // ... + }; + return ; +} +``` + +Next.js์—์„œ๋Š” ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(Server Components)๋กœ ๊ฐ„์ฃผ๋ฉ๋‹ˆ๋‹ค. + +๊ทธ๋ž˜์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ(Client Components)๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•ด "use client" ์ง€์‹œ์–ด๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +๋˜ํ•œ "use server" ์ง€์‹œ์–ด๋„ ์žˆ์ง€๋งŒ, ์ด๋Š” ์„œ๋ฒ„ ์•ก์…˜(Server Actions)์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. + +์„œ๋ฒ„ ์•ก์…˜์€ ํด๋ผ์ด์–ธํŠธ์—์„œ ํ˜ธ์ถœ๋˜์ง€๋งŒ ์„œ๋ฒ„์—์„œ ์‹คํ–‰๋˜๋Š” RPC(์›๊ฒฉ ํ”„๋กœ์‹œ์ € ํ˜ธ์ถœ)์™€ ์œ ์‚ฌํ•œ ๋™์ž‘์„ ํ•ฉ๋‹ˆ๋‹ค. + +์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•  ๋•Œ๋Š” ์ด ์ง€์‹œ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” ํด๋ผ์ด์–ธํŠธ์—์„œ๋งŒ ๋ Œ๋”๋ง๋œ๋‹ค๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, Next.js๋Š” ์ดˆ๊ธฐ HTML์„ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. + +๊ทธ ๊ฒฐ๊ณผ ๋ธŒ๋ผ์šฐ์ €๋Š” ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฆ‰์‹œ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ดํ›„์— ํ•˜์ด๋“œ๋ ˆ์ด์…˜(hydration)์„ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. + +## ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์™€ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์˜ ๊ด€๊ณ„ + +ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋งŒ ๋ช…์‹œ์ ์œผ๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์ฆ‰, ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—์„œ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. + +์ด๋Š” ์žฌ๋ Œ๋”๋ง ๋ฌธ์ œ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. + +๊ทธ๋Ÿฌ๋‚˜ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์˜ ์„œ๋ธŒ ํŠธ๋ฆฌ์— ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํฌํ•จํ•  ์ˆ˜๋Š” ์žˆ์Šต๋‹ˆ๋‹ค. + +์ด๋Š” children prop์„ ํ†ตํ•ด ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค. + +ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‹คํ–‰๋˜๋ฉฐ ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ์„ ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜ ์ž์ฒด ์ƒํƒœ๋ฅผ ์ •์˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ž์ฃผ ์žฌ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. + +ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žฌ๋ Œ๋”๋ง๋  ๋•Œ, ๊ทธ ์„œ๋ธŒ ํŠธ๋ฆฌ๋„ ์žฌ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. + +ํ•˜์ง€๋งŒ ์„œ๋ธŒ ํŠธ๋ฆฌ์— ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ์žฌ๋ Œ๋”๋ง๋ ๊นŒ์š”? + +์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ์‹คํ–‰๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +์ด๋Ÿฌํ•œ ์ด์œ ๋กœ React ํŒ€์€ ์ด๋Ÿฌํ•œ ์ œํ•œ์„ ๋‘์—ˆ์Šต๋‹ˆ๋‹ค. + +ํ•˜์ง€๋งŒ ์ž ๊น๋งŒ์š”! ์‚ฌ์‹ค ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—์„œ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +๋‹ค๋งŒ, ์ด๋Š” ์ผ๋Œ€์ผ ๊ด€๊ณ„๊ฐ€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค. + +๋งŒ์•ฝ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ์„œ๋ฒ„ API๋ฅผ ์‚ฌ์šฉ ์ค‘์ด๋ผ๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒƒ์ด๋ฉฐ, ๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์˜ ์ฝ”๋“œ๊ฐ€ ๋ธŒ๋ผ์šฐ์ €๋กœ "๋…ธ์ถœ"๋ฉ๋‹ˆ๋‹ค. + +์ด๊ฒƒ์€ RSCs(React Server Components)๋ฅผ ์ž‘์—…ํ•  ๋•Œ ๋งค์šฐ ์ค‘์š”ํ•œ ์ฐจ์ด์ ์ž…๋‹ˆ๋‹ค. + +์ด ๋ฏธ๋ฌ˜ํ•œ ์ ์„ ๋ฐ˜๋“œ์‹œ ์—ผ๋‘์— ๋‘์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +## ๋ Œ๋”๋ง ๋ผ์ดํ”„์‚ฌ์ดํด + +๋‹ค์Œ์€ Next.js๊ฐ€ ์ฝ˜ํ…์ธ ๋ฅผ ์ŠคํŠธ๋ฆฌ๋ฐํ•˜๋Š” ์ˆœ์„œ์ž…๋‹ˆ๋‹ค: + +1. ์•ฑ ๋ผ์šฐํ„ฐ๋Š” ํŽ˜์ด์ง€์˜ URL์„ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ(Server Component)์— ๋งค์นญ์‹œํ‚ค๊ณ , ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ๋ฅผ ๊ตฌ์ถ•ํ•œ ํ›„, ์„œ๋ฒ„ ์ธก React์— ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์™€ ๋ชจ๋“  ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋ผ๊ณ  ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค. + +2. ๋ Œ๋”๋ง ์ค‘์— React๋Š” "RSC ํŽ˜์ด๋กœ๋“œ(RSC Payload)"๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. RSC ํŽ˜์ด๋กœ๋“œ๋Š” ํŽ˜์ด์ง€์— ๋Œ€ํ•œ ์ •๋ณด์™€ ๋ฐ˜ํ™˜๋  ๋‚ด์šฉ์„ Next.js์— ์•Œ๋ฆฌ๋ฉฐ, ๋™์•ˆ ๋Œ€์ฒดํ•  ๋‚ด์šฉ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. + +3. React๊ฐ€ ์„œ์ŠคํŽœ๋“œ๋œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋‚˜๋ฉด, ํ•ด๋‹น ์„œ๋ธŒ ํŠธ๋ฆฌ์˜ ๋ Œ๋”๋ง์„ ์ผ์‹œ ์ค‘์ง€ํ•˜๊ณ  ์„œ์ŠคํŽœ๋“œ๋œ ์ปดํฌ๋„ŒํŠธ์˜ ๋Œ€์ฒด ๊ฐ’์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + +4. React๊ฐ€ ๋งˆ์ง€๋ง‰ ์ •์  ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ฉด, Next.js๋Š” ์ƒ์„ฑ๋œ HTML๊ณผ RSC ํŽ˜์ด๋กœ๋“œ๋ฅผ ์ค€๋น„ํ•˜์—ฌ ํ•˜๋‚˜ ์ด์ƒ์˜ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„์–ด ํด๋ผ์ด์–ธํŠธ๋กœ ์ŠคํŠธ๋ฆฌ๋ฐํ•ฉ๋‹ˆ๋‹ค. + +5. ํด๋ผ์ด์–ธํŠธ ์ธก React๋Š” RSC ํŽ˜์ด๋กœ๋“œ์™€ ํด๋ผ์ด์–ธํŠธ ์ธก ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ์ง€์‹œ ์‚ฌํ•ญ์„ ์‚ฌ์šฉํ•˜์—ฌ UI๋ฅผ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋กœ๋“œ๋  ๋•Œ๋งˆ๋‹ค ์ด๋ฅผ ํ•˜์ด๋“œ๋ ˆ์ด์…˜(hydration)ํ•ฉ๋‹ˆ๋‹ค. + +6. ์„œ๋ฒ„๋Š” ์„œ์ŠคํŽœ๋“œ๋œ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ด์ง€๋ฉด ์ด๋ฅผ RSC ํŽ˜์ด๋กœ๋“œ๋กœ ์ŠคํŠธ๋ฆฌ๋ฐํ•ฉ๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์˜ ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋„ ์ด๋•Œ ํ•˜์ด๋“œ๋ ˆ์ด์…˜๋ฉ๋‹ˆ๋‹ค(์„œ์ŠคํŽœ๋“œ๋œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํฌํ•จ๋œ ๊ฒฝ์šฐ). + +RSC ๋ Œ๋”๋ง ๋ผ์ดํ”„์‚ฌ์ดํด์„ ๋ธŒ๋ผ์šฐ์ € ๊ด€์ ์—์„œ ์ž ์‹œ ํ›„์— ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. + +๋‹ค์Œ ๊ทธ๋ฆผ์ด ์šฐ๋ฆฌ๊ฐ€ ๋‹ค๋ฃฌ ๋‹จ๊ณ„๋ฅผ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค. + +![](https://files.smashing.media/articles/forensics-react-server-components/4-wire-diagram-rsc-rendering-lifecycle.jpg) + +# RSC ํŽ˜์ด๋กœ๋“œ + +RSC ํŽ˜์ด๋กœ๋“œ๋Š” ์„œ๋ฒ„๊ฐ€ ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ๋ฅผ ๋ Œ๋”๋งํ•  ๋•Œ ์ƒ์„ฑํ•˜๋Š” ํŠน๋ณ„ํ•œ ๋ฐ์ดํ„ฐ ํ˜•์‹์œผ๋กœ, ๋‹ค์Œ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค: + +- ๋ Œ๋”๋ง๋œ HTML + +- ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง๋  ์ž๋ฆฌ ํ‘œ์‹œ์ž + +- ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์— ๋Œ€ํ•œ ์ฐธ์กฐ + +- ํ˜ธ์ถœํ•ด์•ผ ํ•˜๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์— ๋Œ€ํ•œ ์ง€์‹œ ์‚ฌํ•ญ + +- ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์—์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋กœ ์ „๋‹ฌ๋˜๋Š” ๋ชจ๋“  props. + +RSC ํŽ˜์ด๋กœ๋“œ์— ๋Œ€ํ•ด ํฌ๊ฒŒ ๊ฑฑ์ •ํ•  ํ•„์š”๋Š” ์—†์ง€๋งŒ, RSC ํŽ˜์ด๋กœ๋“œ์— ๋ฌด์—‡์ด ํฌํ•จ๋˜๋Š”์ง€ ์ดํ•ดํ•  ํ•„์š”๋Š” ์žˆ์Šต๋‹ˆ๋‹ค. + +[์ œ๊ฐ€ ๋งŒ๋“  ๋ฐ๋ชจ ์•ฑ](https://github.com/nikolovlazar/rsc-forensics)์˜ ์˜ˆ์‹œ๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. (๊ฐ„๊ฒฐํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์ผ๋ถ€๋ฅผ ์ƒ๋žตํ–ˆ์Šต๋‹ˆ๋‹ค). + +```ts +1:HL["/_next/static/media/c9a5bc6a7c948fb0-s.p.woff2","font",{"crossOrigin":"","type":"font/woff2"}] +2:HL["/_next/static/css/app/layout.css?v=1711137019097","style"] +0:"$L3" +4:HL["/_next/static/css/app/page.css?v=1711137019097","style"] +5:I["(app-pages-browser)/./node_modules/next/dist/client/components/app-router.js",["app-pages-internals","static/chunks/app-pages-internals.js"],""] +8:"$Sreact.suspense" +a:I["(app-pages-browser)/./node_modules/next/dist/client/components/layout-router.js",["app-pages-internals","static/chunks/app-pages-internals.js"],""] +b:I["(app-pages-browser)/./node_modules/next/dist/client/components/render-from-template-context.js",["app-pages-internals","static/chunks/app-pages-internals.js"],""] +d:I["(app-pages-browser)/./src/app/global-error.jsx",["app/global-error","static/chunks/app/global-error.js"],""] +f:I["(app-pages-browser)/./src/components/clearCart.js",["app/page","static/chunks/app/page.js"],"ClearCart"] +7:["$","main",null,{"className":"page_main__GlU4n","children":[["$","$Lf",null,{}],["$","$8",null,{"fallback":["$","p",null,{"children":"๐ŸŒ€ loading products..."}],"children":"$L10"}]]}] +c:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}]... +9:["$","p",null,{"children":["๐Ÿ›๏ธ ",3]}] +11:I["(app-pages-browser)/./src/components/addToCart.js",["app/page","static/chunks/app/page.js"],"AddToCart"] +10:["$","ul",null,{"children":[["$","li","1",{"children":["Gloves"," - $",20,["$... +``` + +๋ฐ๋ชจ ์•ฑ์—์„œ ์ด ์ฝ”๋“œ๋ฅผ ์ฐพ์œผ๋ ค๋ฉด, ๋ธŒ๋ผ์šฐ์ €์˜ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ Elements ํƒญ์„ ์—ด๊ณ  ํŽ˜์ด์ง€ ํ•˜๋‹จ์˜ `