From eeca447746413e4a45b275a7fe5ea8ed4dd897dd Mon Sep 17 00:00:00 2001 From: jayming66 Date: Wed, 26 Jun 2024 13:33:07 +0900 Subject: [PATCH 1/3] =?UTF-8?q?How-React-19-(Almost)-Made-the-Internet-Slo?= =?UTF-8?q?wer=20=EB=B2=88=EC=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ct-19-(Almost)-Made-the-Internet-Slower.md | 186 ++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 June/article/How-React-19-(Almost)-Made-the-Internet-Slower.md diff --git a/June/article/How-React-19-(Almost)-Made-the-Internet-Slower.md b/June/article/How-React-19-(Almost)-Made-the-Internet-Slower.md new file mode 100644 index 0000000..120ec46 --- /dev/null +++ b/June/article/How-React-19-(Almost)-Made-the-Internet-Slower.md @@ -0,0 +1,186 @@ +# [How React 19 (Almost) Made the Internet Slower](https://blog.codeminer42.com/how-react-19-almost-made-the-internet-slower/?utm_source=newsletter.reactdigest.net&utm_medium=referral&utm_campaign=react-19-and-suspense) + +### ๐Ÿ—“๏ธ ๋ฒˆ์—ญ ๋‚ ์งœ: 2024.06.26 + +### ๐Ÿงš ๋ฒˆ์—ญํ•œ ํฌ๋ฃจ: ๋งˆ์Šคํ„ฐ์œ„(๋ช…์žฌ์œ„) + +--- + +Henrique Yuji +Updated On Jun 17, 2024 +Keyword : **Frontend**, **React** + +๋ฆฌ์•กํŠธ(React)๋Š” ์—ฌ์ „ํžˆ [๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๊ณ  ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š”](https://gist.github.com/tkrotoff/b1caa4c3a185629299ec234d2314e190) ์‚ฌ์šฉ๋˜๋Š” UI ํ”„๋ ˆ์ž„์›Œํฌ๋กœ, ๋„ทํ”Œ๋ฆญ์Šค, ์—์–ด๋น„์•ค๋น„, ๋””์Šค์ฝ”๋“œ, ๋ฉ”ํƒ€(ํŽ˜์ด์Šค๋ถ, ์ธ์Šคํƒ€๊ทธ๋žจ, ์™“์ธ ์•ฑ) ๋“ฑ ๋Œ€ํ˜• ์›น์‚ฌ์ดํŠธ์—์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ˆ˜์‹ญ์–ต ๋ช…์ด ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋ฏ€๋กœ, ์ธํ„ฐ๋„ท ํŠธ๋ž˜ํ”ฝ์˜ ์ƒ๋‹น ๋ถ€๋ถ„์ด React์— ์˜ํ•ด ์ฒ˜๋ฆฌ๋œ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์˜ฌํ•ด ์ดˆ ๋ฐœํ‘œ๋œ ๊ธฐ๋Œ€๋ฅผ ๋ชจ์•˜๋˜ React 19๋Š” ๋งŽ์€ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ๊ณผ ๊ฐœ๋ฐœ์ž ๊ฒฝํ—˜(DX) ๊ฐœ์„ ์„ ํฌํ•จํ•˜๊ณ  ์žˆ์ง€๋งŒ, ์ตœ๊ทผ๊นŒ์ง€ ์ฃผ๋ชฉ๋ฐ›์ง€ ๋ชปํ•œ ์ž‘์€ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์—ฌ๋Ÿฌ React ๊ธฐ๋ฐ˜ ์›น์‚ฌ์ดํŠธ์˜ ์„ฑ๋Šฅ์„ ํฌ๊ฒŒ ์ €ํ•˜์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์ž ์žฌ๋ ฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. + +๋ชจ๋“  ๊ฒƒ์€ ๋‹ค์Œ ํŠธ์œ—์—์„œ ์‹œ์ž‘๋˜์—ˆ์Šต๋‹ˆ๋‹ค: + + + +[@TkDodo](https://x.com/TkDodo/status/1800501040766144676): "๋‚ด๊ฐ€ ์ƒ์ƒํ•˜๋Š” ๊ฑด๊ฐ€์š”, ์•„๋‹ˆ๋ฉด React 18๊ณผ 19์—์„œ Suspense๊ฐ€ ๋ณ‘๋ ฌ ํŽ˜์นญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์— ์ฐจ์ด๊ฐ€ ์žˆ๋‚˜์š”? 18์—์„œ๋Š” ๊ฐ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ณ‘๋ ฌ๋กœ ๋ถ„๋ฆฌ๋˜์—ˆ์ง€๋งŒ, 19์—์„œ๋Š” ์—ฐ์†์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค." +์ด๋Š” ๋‘ ๊ฐœ์˜ ์ฟผ๋ฆฌ๋ฅผ ๋ณ‘๋ ฌ๋กœ ์‹คํ–‰ํ•˜๊ณ , ๋‘˜ ๋‹ค ํ•ด๊ฒฐ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฐ ๋‹ค์Œ ์ „์ฒด ์„œ๋ธŒ ํŠธ๋ฆฌ๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. +React 19์—์„œ๋Š” ๋‚ด๊ฐ€ ๋ณด๊ธฐ์—” ์ฟผ๋ฆฌ๋“ค์ด ์ด์ œ ํญํฌ์ˆ˜์ฒ˜๋Ÿผ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. @rickhanlonii๊ฐ€ ์ด๋Ÿฐ ์–˜๊ธฐ๋ฅผ ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™์€๋ฐ ์ง€๊ธˆ์€ evidence๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. + +--- + + + +[@AdamRackis](https://x.com/AdamRackis/status/1800588094560772224) : ์ด๋Š” ์ดํ•ดํ•  ์ˆ˜ ์—†๋Š”, ๋ฏธ์นœ ๋ณ€ํ™”์ž…๋‹ˆ๋‹ค. ๋Œ“๊ธ€์— ๋”ฐ๋ฅด๋ฉด ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์— ์ ์šฉ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค๋งŒ, ๋ณ‘๋ ฌ ํŽ˜์นญ์€ ์—ฌ์ „ํžˆ RSC์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. +์ด๋Š” react-query๋ฅผ ๋ง์น˜๋ฉฐ, React๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์œ ์ผํ•œ ์ข‹์€ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. +๋ƒ‰์ •ํ•œ ํŒ๋‹จ์ด ์žˆ๊ธฐ๋ฅผ ๋ฐ”๋ผ์ง€๋งŒ, ๊ทธ๋Ÿฌ์ง€ ์•Š์„ ๊ฒƒ ๊ฐ™๋„ค์š”. + +--- + + + +@TkDodo : ์ด์ œ ํ™•์‹คํžˆ React 19์˜ suspense์™€ ํ˜•์ œ ์‚ฌ์ „ ๋ Œ๋”๋ง ๋ณ€๊ฒฝ ์‚ฌํ•ญ์— ๋Œ€ํ•ด ๋ธ”๋กœ๊ทธ์— ์จ์•ผ๊ฒ ์–ด์š”. React ํ•ต์‹ฌ ํŒ€ ์™ธ์—๋Š” ์ด ๊ฑฐ๋ž˜๊ฐ€ ์˜ณ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š” ์‚ฌ๋žŒ์„ ์•„์ง ๋ณธ ์ ์ด ์—†์–ด์š”. v19.0.0์€ ์•„์ง ์ถœ์‹œ๋˜์ง€ ์•Š์•˜์œผ๋‹ˆ, ๊ทธ๋“ค์„ ์žฌ๊ณ ํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์„์ง€๋„ ๋ชฐ๋ผ์š”. + +--- + +[@tannerlinsley](https://x.com/tannerlinsley/status/1800903098464096664) : "๊ทธ๋ž˜์š”, ์ด๊ฑด ๋‚˜์œ ๊ฒฐ์ •์ฒ˜๋Ÿผ ๋Š๊ปด์ ธ์š”, ํŠนํžˆ ๊ธฐ์กด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ž๋™์œผ๋กœ ๋” ๋‚˜์˜๊ฒŒ ๋งŒ๋“ค๊ธฐ ๋•Œ๋ฌธ์—." + +--- + + + +[@AdamRackis](https://x.com/AdamRackis/status/1800663066922963264) : ์ €๋Š” ๊ฐ„์ ˆํžˆ ๋ฐ”๋ผ๊ฑด๋Œ€ Vercel, ๊ทธ๋ฆฌ๊ณ  ์ด์ œ๋Š” ๋”์šฑ ์šฐ๋ ค๋˜๋Š” *React ํ•ต์‹ฌ ํŒ€*์ด ๋ชจ๋“  ์‚ฌ๋žŒ์ด ์ฝ˜ํ…์ธ ๋ฅผ ๊ฐ€๋Šฅํ•œ ๋นจ๋ฆฌ ์•ž์— ๋ณด์—ฌ์ฃผ์–ด ์ง€๋ฃจํ•œ ์‚ฌ์šฉ์ž๊ฐ€ ๋’ค๋กœ ๊ฐ€๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด์ง€ ์•Š๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด ์ตœ์šฐ์„ ์ธ ์ „์ž ์ƒ๊ฑฐ๋ž˜ ์‚ฌ์ดํŠธ๋ฅผ ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋ผ๋Š” ์ ์„ ์ดํ•ดํ•˜๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. + +--- + +
+ +๋„๋ฏธ๋‹‰(TkDodo)์„ ๋ชจ๋ฅด๋Š” ๋ถ„๋“ค์„ ์œ„ํ•ด ์„ค๋ช…ํ•˜์ž๋ฉด, ๊ทธ๋Š” ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” TanStack Query์˜ ์ฃผ์š” ์œ ์ง€ ๊ด€๋ฆฌ์ž ์ค‘ ํ•œ ๋ช…์ด๋ฉฐ, ์ „์„ค์ ์ธ ํƒœ๋„ˆ ๋ฆฐ์ฆ๋ฆฌ(Tanner Linsley)์™€ ํ•จ๊ป˜ ์ผํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. + +ํ•˜์ง€๋งŒ ๋‹ค์‹œ ๋ณธ๋ก ์œผ๋กœ ๋Œ์•„๊ฐ€์„œ, ์—ฌ๊ธฐ์„œ ๋…ผ์˜๋˜๋Š” ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ React 19์—์„œ ๋™์ผํ•œ Suspense ๊ฒฝ๊ณ„ ๋‚ด ํ˜•์ œ ์š”์†Œ์˜ ๋ณ‘๋ ฌ ๋ Œ๋”๋ง์„ ๋น„ํ™œ์„ฑํ™”ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋Š” ํ˜•์ œ ์š”์†Œ ๋‚ด๋ถ€์—์„œ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ ํŽ˜์นญ ํญํฌ์ˆ˜๋ฅผ ๋„์ž…ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. + +๋‹ค์Œ์€ ๊ทธ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค: + + + + + +๊ฐ€์žฅ ํฐ ๋ฌธ์ œ๋Š” ์ด ๋ณ€ํ™”๊ฐ€ ์„ฑ๋Šฅ ์ธก๋ฉด์—์„œ ์ค‘์š”ํ•œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด์ง€๋งŒ, ์ด ํŒจํ„ด์— ์˜์กดํ•˜๋Š” ๋งŽ์€ ์‚ฌ๋žŒ๋“ค์—๊ฒŒ ์˜ํ–ฅ์„ ๋ฏธ์น  ๊ฒƒ์ด๋ผ๋Š” ์ ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ์ด ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ๋‹จ ํ•œ ์ค„์˜ ๋ถˆ๋ช…ํ™•ํ•œ ๊ธ€๋จธ๋ฆฌ๋กœ ์–ธ๊ธ‰๋˜์—ˆ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. + + + +์ œ๊ฐ€ ๋ฐฉ๊ธˆ ๋งํ•œ ๋‚ด์šฉ์ด ํ—ท๊ฐˆ๋ฆฌ์…จ๋‹ค๋ฉด, ๋‹น์‹ ๋งŒ ๊ทธ๋Ÿฐ ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค. ์ €๋„ ์ฒ˜์Œ ์ด ๊ธ€์„ ์ ‘ํ–ˆ์„ ๋•Œ ๊ทธ๋ ‡๊ฒŒ ๋Š๊ผˆ์Šต๋‹ˆ๋‹ค. ๊ฑฑ์ •ํ•˜์ง€ ๋งˆ์„ธ์š”. ๊ณง ๋ชจ๋“  ๊ฒƒ์ด ์ดํ•ด๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +## Suspense ๋ณต์Šต + +์ด ๋‚ด์šฉ์„ ์ดํ•ดํ•˜๋ ค๋ฉด ๋จผ์ € React์˜ Suspense์— ๋Œ€ํ•ด ๊ฐ„๋žตํžˆ ๋ณต์Šตํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +Suspense๋Š” ์ž์‹ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋กœ๋”ฉ์„ ๋งˆ์น  ๋•Œ๊นŒ์ง€ ๋Œ€์ฒด ๋‚ด์šฉ์„ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” React ์ปดํฌ๋„ŒํŠธ์ž…๋‹ˆ๋‹ค. ์ž์‹ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ง€์—ฐ ๋กœ๋“œ๋˜๊ฑฐ๋‚˜, Suspense๋ฅผ ์‚ฌ์šฉํ•œ ๋ฐ์ดํ„ฐ ํŽ˜์นญ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์‚ฌ์šฉํ•  ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. + +์‚ฌ์šฉ ์˜ˆ์‹œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค: + +```jsx +}> + + +``` + +Suspense๋Š” ์˜ค๋žซ๋™์•ˆ React API์˜ ์ผ๋ถ€์˜€์ง€๋งŒ, ๊ณต์‹์ ์œผ๋กœ ์Šน์ธ๋œ ์‚ฌ์šฉ๋ฒ•์€ React.lazy์™€ ํ•จ๊ป˜ ์ง€์—ฐ ๋กœ๋”ฉ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์•ฑ์„ ์ฝ”๋“œ ๋ถ„ํ• ํ•˜๊ณ  ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋งŒ ๋ถ„ํ• ๋œ ๋ถ€๋ถ„์„ ๋กœ๋“œํ•˜๋Š” ๋ฐ ๋งค์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. + +React.lazy๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ฒ˜์Œ ์ง€์—ฐ ๋กœ๋“œ๋œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ํ•  ๋•Œ Suspense ๊ฒฝ๊ณ„๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๊ณ , ์ปดํฌ๋„ŒํŠธ ์ฝ”๋“œ๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋•Œ๊นŒ์ง€ ๋Œ€์ฒด ๋‚ด์šฉ์„ ๋ Œ๋”๋งํ•œ ๋‹ค์Œ ์ปดํฌ๋„ŒํŠธ ์ž์ฒด๋ฅผ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. + +์˜ค๋žซ๋™์•ˆ ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ Suspense๋ฅผ ์œ„ํ•œ ๊ณต์‹ ๋ฐ์ดํ„ฐ ํŽ˜์นญ ์ง€์›์ด ์•ฝ์†๋˜์—ˆ์ง€๋งŒ, ์ง€๊ธˆ๊นŒ์ง€ ์‹คํ˜„๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๋งŽ์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(์˜ˆ: TanStack Query)๋Š” React ๋‚ด๋ถ€๋ฅผ ์กฐ์‚ฌํ•˜์—ฌ ์ด๋ฅผ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ ํ˜„์žฌ ๋งŽ์€ ํ”„๋กœ๋•์…˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ํด๋ผ์ด์–ธํŠธ ์ธก ๋ฐ์ดํ„ฐ ํŽ˜์นญ์— Suspense๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. + +## ๋ณ€ํ™” ์ดํ•ดํ•˜๊ธฐ + +ํ˜„์žฌ(React 18.3.1 ๊ธฐ์ค€) ๋™์ผํ•œ Suspense ๊ฒฝ๊ณ„ ๋‚ด์—์„œ ์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ์™€ ํ•จ๊ป˜ Suspense ์ง€์› ๋ฐ์ดํ„ฐ ํŽ˜์นญ ๋˜๋Š” ์ง€์—ฐ ๋กœ๋”ฉ์„ ์‚ฌ์šฉํ•  ๋•Œ, React๋Š” ์ฒซ ๋ฒˆ์งธ ํ˜•์ œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ค‘๋‹จ๋˜๋”๋ผ๋„ ๋ชจ๋“  ํ˜•์ œ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค. + +์‹ค์ œ๋กœ ์ด๋Š” ์ด๋Ÿฌํ•œ ํ˜•์ œ ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฐ์ดํ„ฐ ํŽ˜์นญ ๋˜๋Š” ์ง€์—ฐ ๋กœ๋”ฉ์ด ๋ชจ๋‘ ๋ณ‘๋ ฌ๋กœ ์‹œ์ž‘๋œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. + +์ด ์ƒ๊ฐ์— ๋Œ€ํ•œ ์˜ˆ์‹œ๋ฅผ ๋ณด์‹œ์ฃ  : + +```jsx +function App() { + return ( + <> + + + + + + + ); +} + +const ComponentThatFetchesData = ({ val }) => { + const result = fetchSomethingSuspense(val); + + return
{result}
; +}; +``` + +Demo: https://stackblitz.com/edit/vitejs-vite-x3nv7r?file=src%2FApp.jsx + +์ด ์˜ˆ์‹œ์—์„œ๋Š” (React 18์—์„œ) `fetchSomethingSuspense`๊ฐ€ ์ฒซ ๋ฒˆ์งธ `ComponentThatFetchesData`๋ฅผ ์ค‘๋‹จ์‹œ์ผœ๋„, React๋Š” ์—ฌ์ „ํžˆ ํ˜•์ œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ์‹œ๋„ํ•˜์—ฌ ๊ฐ๊ฐ์˜ ๋ฐ์ดํ„ฐ ํŽ˜์นญ์ด ๋ณ‘๋ ฌ๋กœ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. + +์ด๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์ฝ˜์†”์—์„œ ๊ฐ ๋ฐ์ดํ„ฐ ํŽ˜์นญ์ด ์–ธ์ œ ํŠธ๋ฆฌ๊ฑฐ๋˜๋Š”์ง€ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: + + + +๋ชจ๋“  ๋ฐ์ดํ„ฐ ํŽ˜์นญ์ด ๊ฑฐ์˜ ๋™์‹œ์— ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. + +์ด์ œ ๋™์ผํ•œ ์ฝ”๋“œ๋ฅผ React 19 (canary)์—์„œ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ์–ด๋–ค ์ผ์ด ๋ฐœ์ƒํ•˜๋Š”์ง€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค: + +Demo: https://stackblitz.com/edit/vitejs-vite-55rddj?file=src%2FApp.jsx + + + +์ฝ˜์†”์„ ๋‹ค์‹œ ํ™•์ธํ•ด ๋ณด๋ฉด ์ด์ œ๋Š” ํญํฌ์ˆ˜ ํ˜•ํƒœ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋ฉฐ, ๊ฐ ๋ฐ์ดํ„ฐ ํŽ˜์นญ์ด ์ด์ „ ํŽ˜์นญ์ด ์™„๋ฃŒ๋œ ํ›„์—์•ผ ์‹œ์ž‘๋˜๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์ด๊ฒƒ์€ ๋‹ค์Œ PR์—์„œ ์ผ์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค : +https://github.com/facebook/react/pull/26380 + +์ด PR์— ์˜ํ•ด ๋„์ž…๋œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์ดํ›„, React๋Š” ๋™์ผํ•œ Suspense ๊ฒฝ๊ณ„ ๋‚ด์˜ ๋ชจ๋“  ํ˜•์ œ ์š”์†Œ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ์‹œ๋„ํ•˜๋Š” ๋Œ€์‹ , ์ฒซ ๋ฒˆ์งธ๋กœ ์ค‘๋‹จ๋˜๋Š” ์š”์†Œ์—์„œ ๋ฉˆ์ถ”๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ, ์ฒซ ๋ฒˆ์งธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ์‹œ๋„ํ•œ ํ›„ ์ค‘๋‹จ๋˜๋ฉด, ๋ฐ์ดํ„ฐ ํŽ˜์นญ์ด ์™„๋ฃŒ๋œ ํ›„์—์•ผ ๋‹ค์Œ ํ˜•์ œ ์š”์†Œ๋กœ ๋„˜์–ด๊ฐ€๊ณ , ๋‹ค์‹œ ์ค‘๋‹จ๋ฉ๋‹ˆ๋‹ค. + +์ด ์ƒˆ๋กœ์šด ๋™์ž‘์€ ๋ฐ์ดํ„ฐ ํŽ˜์นญ์„ ์œ„ํ•œ Suspense ์‚ฌ์šฉ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์˜ค๋ž˜๋œ ํŒจํ„ด์œผ๋กœ ๋” ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” React.lazy ์‚ฌ์šฉ์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค. + + + +[@bentonnnnnn](https://x.com/bentonnnnnn/status/1800940807618171270) : ์˜ˆ์ƒ๋Œ€๋กœ ์ด ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ ์ง€์—ฐ ๋กœ๋“œ๋œ ์ปดํฌ๋„ŒํŠธ(react.lazy)์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค. +์ด์ œ ๋” ์ด์ƒ ๋ณ‘๋ ฌ๋กœ ๊ฐ€์ ธ์˜ค์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋กœ๋”ฉ ์‹œ๊ฐ„์€ ๋‘ ํŽ˜์น˜์˜ ํ•ฉ์ด ๋˜๋ฉฐ, ์ด๋Š” ํฐ ํ›„ํ‡ด๋กœ ๊ฐ„์ฃผ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +--- + +## ๊ทผ๊ฑฐ์™€ DX ์˜ํ–ฅ + +์ด ๋ณ€๊ฒฝ์˜ ๊ทผ๊ฑฐ๋Š”, ์‹ค์ œ๋กœ ์ค‘๋‹จ๋˜๊ธฐ ์ „์— ๋ชจ๋“  ํ˜•์ œ ์š”์†Œ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ์‹œ๋„ํ•˜๋Š” ๊ฒƒ์€ ๋น„์šฉ์ด ๋“ค๋ฉฐ, ๋ณธ์งˆ์ ์œผ๋กœ fallback์„ ํ‘œ์‹œํ•˜๋Š” ๊ฒƒ์„ ์ง€์—ฐ์‹œํ‚จ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. ๋˜ํ•œ ์ด ๋ณ€๊ฒฝ์€ React ํŒ€์ด React 18 ์ด์ „์— Suspense๋ฅผ ๋„์ž…ํ•˜๋ฉด์„œ๋ถ€ํ„ฐ ์ถ”์ง„ํ•ด ์˜จ "fetch as you render" ์ ‘๊ทผ ๋ฐฉ์‹๊ณผ ์ผ์น˜ํ•ฉ๋‹ˆ๋‹ค. + +์ด์ƒ์ ์œผ๋กœ๋Š”, ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง ์‹œ ๋ฐ์ดํ„ฐ ํŽ˜์นญ์„ ์‹œ์ž‘ํ•˜๋Š” ๋Œ€์‹ , ๊ฐ€๋Šฅํ•œ ๋นจ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. + +๋น„๋ก ์„ฑ๋Šฅ ๋ฉด์—์„œ๋Š” ์ตœ์ƒ์˜ ์ ‘๊ทผ ๋ฐฉ์‹์ด์ง€๋งŒ, ์ด๋Š” ์ปดํฌ๋„ŒํŠธ์™€ ๋ฐ์ดํ„ฐ ์š”๊ตฌ ์‚ฌํ•ญ์„ ํ•จ๊ป˜ ๋ฐฐ์น˜ํ•˜๋Š” ๊ฒƒ์„ ์–ด๋ ต๊ฒŒ ๋งŒ๋“ค์–ด ๊ฐœ๋ฐœ์ž ๊ฒฝํ—˜(DX)์— ํฐ ๋‹จ์ ์„ ์•ˆ๊ฒจ์ค๋‹ˆ๋‹ค. + +์ด ์ฃผ์ œ์— ๋Œ€ํ•ด ์ด๋ฏธ ๋งŽ์€ ๋…ผ์˜๊ฐ€ ์žˆ์—ˆ๊ณ , ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํŠน๋ณ„ํžˆ ๋งŒ๋“ค์–ด์ง„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์—ฌ๊ธฐ์„œ ๊นŠ์ด ๋‹ค๋ฃจ์ง€๋Š” ์•Š๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ, ์ด ํŠน์ • ๋ฌธ์ œ์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•˜๋Š” ๋ช‡ ๊ฐ€์ง€ ํŠธ์œ—์„ ๋‚จ๊ธฐ๊ฒ ์Šต๋‹ˆ๋‹ค. + + + +[@teemu_taskula](https://x.com/teemu_taskula/status/1800770818097754509) : Dominik์˜ ๊ณ ํ†ต์ด ๋Š๊ปด์ง€๋„ค์š” ๐Ÿ˜Ÿ ์ด๊ฑด React์˜ ์ฃผ์š” ์„ค๊ณ„ ์›์น™์ธ composition์— ๋ฐ˜ํ•˜๋Š” ๊ฒƒ ์•„๋‹Œ๊ฐ€์š”? ์ œ๊ฐ€ ์ œ๋Œ€๋กœ ์ดํ•ดํ•œ ๊ฒŒ ๋งž๋‹ค๋ฉด, ์ด์ œ ๋ณต์žกํ•œ ์‚ฌ์ „ ํŽ˜์นญ ํŠธ๋ฆญ ์—†์ด๋Š” ๋ฐ์ดํ„ฐ ์š”๊ตฌ๋ฅผ ๊ตฌ์„ฑํ•  ์ˆ˜ ์—†๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์•„๋‹ˆ๋ฉด ๋ชจ๋“  ๋ฐ์ดํ„ฐ ํŽ˜์นญ์„ ๊ณตํ†ต ๋ถ€๋ชจ๋กœ ์˜ฌ๋ ค์•ผ ํ•˜์ฃ . +๋ฐ์ดํ„ฐ ํŽ˜์นญ์„ ๊ณตํ†ต ๋ถ€๋ชจ๋กœ ์˜ฌ๋ ค์•ผ ํ•œ๋‹ค๋ฉด Suspense๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์˜๋ฏธ๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€์š”? ์ €๋Š” ๋น„๋™๊ธฐ ์ž‘์—… ์กฐ์ •์„ ๋” ์‰ฝ๊ฒŒ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด Suspense์˜ ๋ชฉ์ ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ view์˜ ๋ฃจํŠธ์—์„œ ๋ฐ์ดํ„ฐ ํŽ˜์นญ์„ ์‹œ์ž‘ํ•ด์•ผ ํ•œ๋‹ค๋ฉด, ์ฐจ๋ผ๋ฆฌ Suspense ์—†์ด ๋ฐ์ดํ„ฐ๋ฅผ ์ฟผ๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ๋‚ซ์Šต๋‹ˆ๋‹ค. + +--- + +์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ์ ์€ ์ปดํฌ๋„ŒํŠธ์™€ ๊ทธ ๋ฐ์ดํ„ฐ ์š”๊ตฌ ์‚ฌํ•ญ์˜ ์ตœ์ ์˜ ์„ฑ๋Šฅ ํŠน์„ฑ๊ณผ ๊ณต๋™ ๋ฐฐ์น˜๋ฅผ ๋™์‹œ์— ๋‹ฌ์„ฑํ•˜๋Š” ๊ฒƒ์ด **์ปดํŒŒ์ผ๋Ÿฌ** ์—†์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋Š” Relay๊ฐ€ ์ˆ˜ํ–‰ํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค. + +## ๊ฒฐ๋ก  + +๋‹คํ–‰ํžˆ๋„ ์ด ์ด์•ผ๊ธฐ๋Š” ํ•ดํ”ผ์—”๋”ฉ์œผ๋กœ ๋๋‚ฌ์Šต๋‹ˆ๋‹ค. ๋งŽ์€ ๊ณต๊ฐœ ๋ฐ˜๋ฐœ, ์—ด๋ค ํ† ๋ก , ๊ทธ๋ฆฌ๊ณ  ์•„๋งˆ๋„ ๋ฐฐํ›„์—์„œ์˜ ์ƒ๋‹นํ•œ ๋…ผ์˜ ๋์—, React ํŒ€์€ ์ด ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ณด๋ฅ˜ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. + + + +[@sophiebits](https://x.com/sophiebits/status/1801663976973209620) : ์ข‹์€ ์†Œ์‹์ž…๋‹ˆ๋‹ค. Suspense์™€ ๊ด€๋ จ๋œ ๋ฌธ์ œ์— ๋Œ€ํ•ด +@rickhanlonii, @en_JS, @acdlite์™€ ๋งŒ๋‚ฌ์Šต๋‹ˆ๋‹ค. + +์šฐ๋ฆฌ๋Š” ๋‹จ์ผ ํŽ˜์ด์ง€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜(SPA)์— ๋Œ€ํ•ด ๋งŽ์€ ๊ด€์‹ฌ์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ํŒ€์ด ์˜ค๋Š˜๋‚  ๋งŽ์€ ์‚ฌ๋žŒ๋“ค์ด ์ด ๊ธฐ๋Šฅ์— ์˜์กดํ•˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์ž˜๋ชป ํŒ๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค. +์—ฌ์ „ํžˆ ํ”„๋ฆฌ๋กœ๋”ฉ์„ ๊ถŒ์žฅํ•˜์ง€๋งŒ, ํ•ญ์ƒ ์‹ค์šฉ์ ์ด์ง€ ์•Š๋‹ค๋Š” ๊ฒƒ์„ ์ธ์‹ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. +์ข‹์€ ํ•ด๊ฒฐ์ฑ…์„ ์ฐพ์„ ๋•Œ๊นŒ์ง€ React 19.0 ๋ฆด๋ฆฌ์Šค๋ฅผ ๋ณด๋ฅ˜ํ•  ๊ณ„ํš์ž…๋‹ˆ๋‹ค. +์ถ”๊ฐ€ ์†Œ์‹์ด ์žˆ์„ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค. + +--- + +์ด๊ฒƒ์€ ์ปค๋ฎค๋‹ˆํ‹ฐ๊ฐ€ Meta์™€ Vercel ์™ธ๋ถ€์—์„œ React๊ฐ€ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€์— ๋Œ€ํ•œ ๊ณ ๋ ค ์—†์ด ๋„์ž…๋œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์— ๋ฐ˜๋ฐœํ•œ ์ฒซ ๋ฒˆ์งธ ์‚ฌ๋ก€๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. React ํŒ€๊ณผ ํŠนํžˆ Vercel์ด RSCs๋ฅผ React๋กœ ๊ตฌ์ถ•ํ•˜๋Š” ๊ธฐ๋ณธ ์š”์†Œ๋กœ ๋งŒ๋“ค๋ ค๋Š” ์ถ”์ง„์ด ๊ทธ ํ•œ ์‚ฌ๋ก€์ž…๋‹ˆ๋‹ค. + +React์˜ ์œ ์ง€ ๊ด€๋ฆฌ์ž๋“ค์ด React์˜ ๋ฏธ๋ž˜๋ฅผ ์œ„ํ•ด ์ตœ์„ ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋Š” ๊ฒƒ๊ณผ ์ปค๋ฎค๋‹ˆํ‹ฐ์˜ ์˜๊ฒฌ ์‚ฌ์ด์— ๋ถˆ์ผ์น˜๊ฐ€ ๋ช…ํ™•ํžˆ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜ ๋ฌธ์ œ๋“ค์ด ๋” ์‹ฌํ™”๋ ์ง€๋Š” ์•„์ง ์ง€์ผœ๋ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. From 2815810b370892d2a474ab22edf19f05695cf073 Mon Sep 17 00:00:00 2001 From: jayming66 Date: Mon, 8 Jul 2024 01:00:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?docs:=20wait=20for=20pening=20-=20=EC=84=9C?= =?UTF-8?q?=EC=8A=A4=ED=8E=9C=EC=8A=A4=20=EC=95=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=A6=98=20=ED=83=90=ED=97=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nding:-A-Suspense-algorithm-exploration.md | 263 ++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 June/article/Wait-for-pending:-A-Suspense-algorithm-exploration.md diff --git a/June/article/Wait-for-pending:-A-Suspense-algorithm-exploration.md b/June/article/Wait-for-pending:-A-Suspense-algorithm-exploration.md new file mode 100644 index 0000000..fea6492 --- /dev/null +++ b/June/article/Wait-for-pending:-A-Suspense-algorithm-exploration.md @@ -0,0 +1,263 @@ +## ๐Ÿ”— [Wait for pending: A Suspense algorithm exploration](https://dev.to/alexandereardon/wait-for-pending-a-not-great-alternative-suspense-algorithm-1gdl) + +### ๐Ÿ—“๏ธ ๋ฒˆ์—ญ ๋‚ ์งœ: 2024.07.08 + +### ๐Ÿงš ๋ฒˆ์—ญํ•œ ํฌ๋ฃจ: ๋งˆ์Šคํ„ฐ์œ„(๋ช…์žฌ์œ„) + +--- + +Alex Reardon +Updated On Jun 25, 2024 +Keyword : **React**, **Javascript** + +React 19์˜ `` ํƒ€์ด๋ฐ์— ๋Œ€ํ•œ [ํฅ๋ฏธ๋กœ์šด ๋…ผ์˜](https://github.com/facebook/react/issues/29898)๊ฐ€ ์ง„ํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค. + +์ด ๊ธ€์—์„œ๋Š” `` ๊ฒฝ๊ณ„ ๋‚ด์˜ ๋ชจ๋“  ๋Œ€๊ธฐ ์ค‘์ธ promise๊ฐ€ ํ•ด๊ฒฐ๋œ ํ›„์— ๋‹ค์‹œ ๋ Œ๋”๋ง์„ ์‹œ๋„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์–ด๋–ป๊ฒŒ ์ƒ๊ธธ์ง€ ํƒ๊ตฌํ•ฉ๋‹ˆ๋‹ค. + +> ์ด๋Š” ์ฒ˜์Œ์—๋Š” ๋ฉ”๋ชจ์žฅ์— ์ ์–ด๋ณธ ์•„์ด๋””์–ด์—์„œ ์ถœ๋ฐœํ•ด ์ œ์•ˆ์„œ๋กœ ๋ฐœ์ „ํ–ˆ์ง€๋งŒ, ์ ‘๊ทผ ๋ฐฉ์‹์— ๋ฌธ์ œ๊ฐ€ ์žˆ์Œ์„ ๋ฐœ๊ฒฌํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๊ธฐ๋กํ•˜๊ณ  ๊ณต์œ ํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋กœ ์ธํ•ด ๋” ๋‚˜์€ ์•„์ด๋””์–ด๊ฐ€ ๋‚˜์˜ฌ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค! + +### TLDR + +'Wait for pending'์€ react@18๊ณผ react@19(alpha) `` ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํฅ๋ฏธ๋กœ์šด ๋ณ€ํ˜•์ž…๋‹ˆ๋‹ค. ํ‰๋ฉด ๋น„๋™๊ธฐ ํŠธ๋ฆฌ(flat async tree)์—์„œ๋Š” 'wait for pending'์ด ๋น ๋ฅธ ๋ Œ๋” ํ•จ์ˆ˜ ํ˜ธ์ถœ๊ณผ ์ตœ์†Œํ•œ์˜ ์žฌ๋ Œ๋”๋ง์„ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ค‘์ฒฉ๋œ ๋น„๋™๊ธฐ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋Š” ํŠธ๋ฆฌ์—์„œ๋Š” ์ž์‹ ๋น„๋™๊ธฐ ์ปดํฌ๋„ŒํŠธ์˜ ์ดˆ๊ธฐ ๋ Œ๋”๋ง์ด react@18 ์•Œ๊ณ ๋ฆฌ์ฆ˜๋ณด๋‹ค ๋Š๋ ค์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +### Background + +**react@18์˜ ``** + +- ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๋ฅผ `` ๊ฒฝ๊ณ„ ๋‚ด์—์„œ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. +- ์–ด๋–ค promise๊ฐ€ resolve ๋  ๋•Œ๋งˆ๋‹ค ๋ฆฌ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. +- ๋” ์ด์ƒ promise๋ฅผ ๋˜์ง€๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์—†์„ ๋•Œ๊นŒ์ง€ ๊ณ„์†ํ•ฉ๋‹ˆ๋‹ค. + +๊ฒฐ๊ณผ์ ์œผ๋กœ ๋งŽ์€ ์žฌ๋ Œ๋”๋ง์ด ๋ฐœ์ƒํ•˜์ง€๋งŒ, 'fetch in render' ํ˜ธ์ถœ์˜ ๋ณ‘๋ ฌํ™”๋ฅผ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๊ณ , ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ตœ๋Œ€ํ•œ ๋นจ๋ฆฌ ๋ Œ๋”๋ง๋˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. + +**react@19 (alpha)์˜ ``** + +- ์ปดํฌ๋„ŒํŠธ๊ฐ€ promise๋ฅผ ๋˜์งˆ ๋•Œ tree ๋ Œ๋”๋ง์„ ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค. +- promise๊ฐ€ resolve๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค. +- tree๋ฅผ ๋ฆฌ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. +- ๋” ์ด์ƒ promise๋ฅผ ๋˜์ง€๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์—†์„ ๋•Œ๊นŒ์ง€ ๊ณ„์†ํ•ฉ๋‹ˆ๋‹ค. + +์ตœ์†Œํ•œ์˜ fl๋ Œ๋”๋ง์ด ๋ฐœ์ƒํ•˜์ง€๋งŒ, 'fetch in render' ํ˜ธ์ถœ์ด ์ˆœ์ฐจ์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค(ํญํฌ์ˆ˜ ํ˜•ํƒœ(waterfall)). + +### 'Wait for pending' ์•Œ๊ณ ๋ฆฌ์ฆ˜ + +`` ํƒ€์ด๋ฐ('Wait for pending')์— ๋Œ€ํ•œ ์•„์ด๋””์–ด: + +- ํ˜•์ œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ•ญ์ƒ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. +- ๋ชจ๋“  ํ˜„์žฌ ๋˜์ ธ์ง„ promise๊ฐ€ ํ•ด๊ฒฐ๋  ๋•Œ๊นŒ์ง€ ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฆฌ๋ Œ๋”๋งํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. + +์–ด๋–ป๊ฒŒ ๋˜๋Š”์ง€ ๋ด…์‹œ๋‹ค! + +'Wait for pending'์€ ํ˜„์žฌ์˜ react@18 ``์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค. ๋‹จ, ์–ด๋–ค promise๊ฐ€ resolve ๋  ๋•Œ๋งˆ๋‹ค ๋ชจ๋“  ์ž์‹์„ ๋ Œ๋”๋งํ•˜๋Š” ๋Œ€์‹ , ํ˜„์žฌ ๋˜์ ธ์ง„ ๋ชจ๋“  promise๊ฐ€ resolve๋  ๋•Œ๋งŒ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค. + +- ํ˜•์ œ ๊ฐ„ 'fetch in render'๊ฐ€ ๋ณ‘๋ ฌ fetch๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. +- ์—ฌ์ „ํžˆ pre-fetching์— ์ข‹์€ story๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. +- ๋ฆฌ๋ Œ๋”๋ง์œผ๋กœ ์ธํ•œ ๋‚ญ๋น„๋ฅผ ์ค„์ž…๋‹ˆ๋‹ค. +- ๋น„์‹ผ ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง์ด `throw`ํ•˜๋Š” ํ˜•์ œ๋“ค๊ณผ ํ•จ๊ป˜ ๋ฐœ์ƒํ•ด๋„ ์—ฌ์ „ํžˆ ์ค‘๋ณต๋ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ ์–ด๋„ ์ด๋Ÿฌํ•œ ์ค‘๋ณต ๋ Œ๋”๋ง์ด ์ค„์–ด๋“ญ๋‹ˆ๋‹ค. +- ๐Ÿ‘Ž ์ค‘์ฒฉ๋œ 'fetch in render' ํ˜ธ์ถœ์„ ๋Š๋ฆฌ๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (์•„๋ž˜ ์ฐธ์กฐ). + +๋Œ€๋žต์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ + +1. ์ž์‹๋“ค์„ ๋ Œ๋”ํ•œ๋‹ค. +2. ๋˜์ ธ์ง„ promise๊ฐ€ ์—†์œผ๋ฉด ์™„๋ฃŒ - ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด 3๋‹จ๊ณ„๋กœ ์ด๋™ํ•œ๋‹ค. +3. ๋ชจ๋“  promise resolve ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฐ๋‹ค. +4. 1๋‹จ๊ณ„๋กœ ๋Œ์•„๊ฐ„๋‹ค. + +### Example 1: Only siblings + +```jsx + + + + +``` + +ํ•ด๋‹น ์˜ˆ์‹œ์—์„œ, `A`์™€ `B` ๋‘˜๋‹ค ๊ทธ๋“ค์˜ ๋ Œ๋”์— ๋ฐ์ดํ„ฐ๋ฅผ ์œ„ํ•œ `fetch`๊ฐ€ ์žˆ๋‹ค. + +**react@18** + +Render 1 + +- `A` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง +- `B` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 2 + +- `A`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 3 + +- `B`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋จ + +**react@19 alpha timing** + +Render 1 + +- `A` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 2 + +- `A`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 3 + +- `B`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋จ + +๐Ÿ˜ข ๋ Œ๋”๋ง์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋ฉด(promise๋ฅผ ๋˜์ง€๋ฉด) ํญํฌ์ˆ˜(waterfall)๊ฐ€ ๋ฐœ์ƒํ•จ +๐Ÿ˜Š ์ž ์žฌ์ ์œผ๋กœ ๋น„์šฉ์ด ๋งŽ์ด ๋“œ๋Š” ์ปดํฌ๋„ŒํŠธ์˜ ๊ณผ๋„ํ•œ ๋ฆฌ๋ Œ๋”๋ง์„ ๋ฐฉ์ง€ํ•จ + +**Wait for pending** + +Render 1 + +- `A` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง +- `B` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง +- **`A`์™€ `B`๊ฐ€ resolve ๋˜๊ธธ ๊ธฐ๋‹ค๋ฆผ** + +Render 2 + +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋จ + +โœ… ์ด ๊ฒฝ์šฐ, ์ œ์•ˆ๋œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ํ›Œ๋ฅญํ•œ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค! + +### Example 2: children๊ณผ ํ•จ๊ป˜์ผ ๋•Œ + +์—ฌ๊ธฐ์„œ 'wait for pending' ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๋ถ€๋‹ด์„ ๋Š๋ผ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. + +์ด์ œ `A`๊ฐ€ `ChildX`์™€ `ChildY`๋ฅผ ์ž์‹์œผ๋กœ ๋ Œ๋”๋งํ•˜๋Š”๋ฐ, ์ด๋“ค ๋˜ํ•œ 'fetch in render'๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. + +```jsx + + + + + + + + +``` + +**react@18** + +Render 1 + +- `A` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง +- `B` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 2 + +- `A`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง +- `B`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 3 + +- `ChildX`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง +- `B`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 4 + +- `ChildY`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 5 + +- `B`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋จ + +โœ… ChildX์™€ ChildY๊ฐ€ ๊ฐ€๋Šฅํ•œ ๋นจ๋ฆฌ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. +๐Ÿ˜ข ๋งŽ์€ ์ค‘๋ณต ์žฌ๋ Œ๋”๋ง์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. + +**react@19 alpha timing** + +Render 1 + +- `A` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง + +Render 2 + +- `A`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, `B`๊ฐ€ promise ๋˜์ง + +Render 3 + +- `ChildX`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, `ChildY`๊ฐ€ promise ๋˜์ง + +Render 4 + +- `ChildY`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, `B`๊ฐ€ promise ๋˜์ง + +Render 5 + +- `B`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋จ + +**์ œ์•ˆํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜** + +Render 1 + +- `A` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง +- `B` ๋ Œ๋”๋˜์ง€๋งŒ, promise ๋˜์ง +- **`A`์™€ `B`๊ฐ€ resolve ๋˜๊ธธ ๊ธฐ๋‹ค๋ฆผ** + +Render 2 + +- `A`์™€ `B`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋˜์ง€๋งŒ, promise ๋˜์ง +- `B`๊ฐ€ ๋ Œ๋”๋ง๋จ +- **`ChildX`์™€ `ChildY`๊ฐ€ resolve ๋˜๊ธธ ๊ธฐ๋‹ค๋ฆผ** + +Render 3 + +- `ChildX`์™€ `ChildY`์˜ promise๊ฐ€ resolve๋จ +- `A`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildX`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `ChildY`๊ฐ€ ๋ Œ๋”๋ง๋จ +- `B`๊ฐ€ ๋ Œ๋”๋ง๋จ + +โœ… react@18 ์•Œ๊ณ ๋ฆฌ์ฆ˜๋ณด๋‹ค ์ค‘๋ณต ๋ Œ๋”๋ง์ด ํ›จ์”ฌ ์ ์Šต๋‹ˆ๋‹ค. +๐Ÿ‘Ž ChildX์™€ ChildY๋Š” B๊ฐ€ ํ•ด๊ฒฐ๋˜๊ธฐ ์ „๊นŒ์ง€ 'fetch in render' ํ˜ธ์ถœ์„ ์‹œ์ž‘ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์ด๋“ค์€ ๋ถ€๋ชจ์˜ ๊ฐ€์žฅ ๋Š๋ฆฐ ํ˜•์ œ๊ฐ€ ํ•ด๊ฒฐ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ ค์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค. +๐Ÿค” react@19 ์•Œ๊ณ ๋ฆฌ์ฆ˜๋ณด๋‹ค ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๊ฐ€ ๋” ๋งŽ์ด ๋˜์ง€๋งŒ, react@18๋ณด๋‹ค ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์˜ ์ดˆ๊ธฐ ๋ Œ๋”๋ง ์‹œ์ž‘์ด ๋” ๋Š๋ฆฝ๋‹ˆ๋‹ค. + +### ๋งˆ๋ฌด๋ฆฌ ์ƒ๊ฐ + +'Wait for pending'์€ ํฅ๋ฏธ๋กœ์šด ์ ‘๊ทผ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. + +flat async trees์—์„œ๋Š” 'wait for pending'์ด ๋ Œ๋” ํ•จ์ˆ˜ ํ˜ธ์ถœ์„ ๋น ๋ฅด๊ฒŒ ํ•˜๊ณ  ๋ฆฌ๋ Œ๋”๋ง์„ ์ตœ์†Œํ™”ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ค‘์ฒฉ๋œ ๋น„๋™๊ธฐ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋Š” ํŠธ๋ฆฌ์—์„œ๋Š” ์ž์‹ ๋น„๋™๊ธฐ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ดˆ๊ธฐ ๋ Œ๋”๋ง์„ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์— ๋ถ€๋ชจ ํ˜•์ œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง์„ ์™„๋ฃŒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ค‘์ฒฉ๋œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋„คํŠธ์›Œํฌ ํ˜ธ์ถœ๊ณผ ๊ฐ™์€ ๋น„์šฉ์ด ๋งŽ์ด ๋“œ๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ, ๊ฐ€๋Šฅํ•œ ํ•œ ๋นจ๋ฆฌ ์ดˆ๊ธฐ ๋ Œ๋”๋ง์„ ํŠธ๋ฆฌ๊ฑฐํ•˜๋Š” ๊ฒƒ์ด ์ด์ƒ์ ์ž…๋‹ˆ๋‹ค(react@18 ์•Œ๊ณ ๋ฆฌ์ฆ˜). 'Wait for pending'์€ react@19 ์ ‘๊ทผ ๋ฐฉ์‹๊ณผ ์œ ์‚ฌํ•˜์ง€๋งŒ, ๊ฐ ๋ ˆ๋ฒจ์ด ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +๋‹ค๋ฅธ `` ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์–ด๋–ป๊ฒŒ ์ƒ๊ธธ์ง€ ์ƒ๊ฐํ•ด๋ณด๋Š” ๊ฒƒ์€ ํฅ๋ฏธ๋กœ์› ์Šต๋‹ˆ๋‹ค! ์—ฌ๊ธฐ๊นŒ์ง€ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜…. + +Cheers From dd5e1cb3b9797ce63710e865905b1a29de9c2a4f Mon Sep 17 00:00:00 2001 From: jayming66 Date: Mon, 8 Jul 2024 01:04:26 +0900 Subject: [PATCH 3/3] =?UTF-8?q?7=EC=9B=94=20=EA=B8=80=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Wait-for-pending:-A-Suspense-algorithm-exploration.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {June/article => July}/Wait-for-pending:-A-Suspense-algorithm-exploration.md (100%) diff --git a/June/article/Wait-for-pending:-A-Suspense-algorithm-exploration.md b/July/Wait-for-pending:-A-Suspense-algorithm-exploration.md similarity index 100% rename from June/article/Wait-for-pending:-A-Suspense-algorithm-exploration.md rename to July/Wait-for-pending:-A-Suspense-algorithm-exploration.md