Skip to content

Commit

Permalink
Update July/article/Enhancing-The-New-York-Times-Web-Performance-withโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆ-React-18.md

Co-authored-by: MYONG JAEWI <[email protected]>
  • Loading branch information
lurgi and Jaymyong66 authored Jul 20, 2024
1 parent 52b4b24 commit 1408129
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ return <div dangerouslySetInnerHTML={{ __html: embeddedInteractiveString }} />;

React 18์˜ ๋„์ž…๊ณผ ํ•จ๊ป˜ ๋” ์—„๊ฒฉํ•œ hydration ๋ถˆ์ผ์น˜ ์š”๊ตฌ ์‚ฌํ•ญ์ด ๋“ฑ์žฅํ–ˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ๊ทœ์น™์— ๋”ฐ๋ฅด๋ฉด, ์ดˆ๊ธฐ ๋ธŒ๋ผ์šฐ์ € ๋กœ๋“œ์™€ ํด๋ผ์ด์–ธํŠธ ์ธก hydration ์‚ฌ์ด์— ๋ฐœ์ƒํ•˜๋Š” ๋ชจ๋“  DOM ์ˆ˜์ •์€ ํด๋ผ์ด์–ธํŠธ ์ธก ๋ Œ๋”๋ง์œผ๋กœ์˜ fallback์„ ํŠธ๋ฆฌ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์Šคํฌ๋ฆฝํŠธ ํƒœ๊ทธ๊ฐ€ hydration ์ „์— "server-test" ์š”์†Œ๋ฅผ ์ˆ˜์ •ํ•˜๋”๋ผ๋„ hydration ๋ถˆ์ผ์น˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด React๋Š” ์„œ๋ฒ„ ๋ Œ๋”๋ง๋œ ์ฝ˜ํ…์ธ ๋ฅผ ํ๊ธฐํ•˜๊ณ  ํด๋ผ์ด์–ธํŠธ ์ธก ๋ Œ๋”๋ง์œผ๋กœ fallbackํ•˜์—ฌ ์Šคํฌ๋ฆฝํŠธ์˜ ์˜ํ–ฅ์„ ์‹ค์งˆ์ ์œผ๋กœ ๋ฌดํšจํ™”ํ•ฉ๋‹ˆ๋‹ค. ์ด์ „ ๋ฒ„์ „์˜ React์—์„œ๋Š” hydration ๋ถˆ์ผ์น˜๊ฐ€ ๋ฐœ์ƒํ•˜๋”๋ผ๋„ DOM์˜ ๋ฒ„์ „์„ ๋ฌดํšจ ์ƒํƒœ๋กœ ๋‘๋Š” ๊ฒƒ์„ ์„ ํƒํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ๊ฒฝํ—˜ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

์‹ค์ œ๋กœ ์ด๊ฒƒ์ด ์˜๋ฏธํ•˜๋Š” ๋ฐ”๋Š” ๋ฌด์—‡์ผ๊นŒ์š”? ํด๋ผ์ด์–ธํŠธ์—์„œ `dangerouslySetInnerHTML` ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•  ๋•Œ, ๊ทธ ์•ˆ์— `<script>` ํƒœ๊ทธ๊ฐ€ ํฌํ•จ๋œ HTML ์กฐ๊ฐ์€ ๋ธŒ๋ผ์šฐ์ € ๋ณด์•ˆ ๊ณ ๋ ค ์‚ฌํ•ญ์œผ๋กœ ์ธํ•ด ์‹คํ–‰๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Š” `dangerouslySetInnerHTML` ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜ํ™” ๋ถˆ์ผ์น˜๋กœ ์ธํ•ด ํด๋ผ์ด์–ธํŠธ์—์„œ ๋‹ค์‹œ ๋ Œ๋”๋ง๋œ ๋ชจ๋“  ์ž„๋ฒ ๋””๋“œ ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ๊ฐ€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์‹คํ–‰๋˜์ง€ ์•Š์€ ๊ฒƒ์ฒ˜๋Ÿผ ๋ Œ๋”๋ง๋œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์œ„์˜ ์˜ˆ์‹œ์—์„œ ํ…์ŠคํŠธ ์ฝ˜ํ…์ธ ๋Š” "server"์—์„œ "client"๋กœ ๋ณ€๊ฒฝ๋˜์ง€๋งŒ, ์ˆ˜ํ™” ๋ถˆ์ผ์น˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด "server"๋กœ ๋‹ค์‹œ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ผ๋ถ€ ์ž„๋ฒ ๋””๋“œ ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ๊ฐ€ ์˜ˆ์ƒ ๋ Œ๋”๋ง๊ณผ ํฌ๊ฒŒ ๋‹ค๋ฅด๊ฒŒ ๋ณด์ด๊ฒŒ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
์‹ค์ œ๋กœ ์ด๊ฒƒ์ด ์˜๋ฏธํ•˜๋Š” ๋ฐ”๋Š” ๋ฌด์—‡์ผ๊นŒ์š”? ํด๋ผ์ด์–ธํŠธ์—์„œ `dangerouslySetInnerHTML` ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•  ๋•Œ, ๊ทธ ์•ˆ์— `<script>` ํƒœ๊ทธ๊ฐ€ ํฌํ•จ๋œ HTML ์กฐ๊ฐ์€ ๋ธŒ๋ผ์šฐ์ € ๋ณด์•ˆ ๊ณ ๋ ค ์‚ฌํ•ญ์œผ๋กœ ์ธํ•ด ์‹คํ–‰๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Š” `dangerouslySetInnerHTML` ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ hydration ๋ถˆ์ผ์น˜๋กœ ์ธํ•ด ํด๋ผ์ด์–ธํŠธ์—์„œ ๋‹ค์‹œ ๋ Œ๋”๋ง๋œ ๋ชจ๋“  ์ž„๋ฒ ๋””๋“œ ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ๊ฐ€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์‹คํ–‰๋˜์ง€ ์•Š์€ ๊ฒƒ์ฒ˜๋Ÿผ ๋ Œ๋”๋ง๋œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์œ„์˜ ์˜ˆ์‹œ์—์„œ ํ…์ŠคํŠธ ์ฝ˜ํ…์ธ ๋Š” "server"์—์„œ "client"๋กœ ๋ณ€๊ฒฝ๋˜์ง€๋งŒ, hydration ๋ถˆ์ผ์น˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด "server"๋กœ ๋‹ค์‹œ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ผ๋ถ€ ์ž„๋ฒ ๋””๋“œ ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ๊ฐ€ ์˜ˆ์ƒ ๋ Œ๋”๋ง๊ณผ ํฌ๊ฒŒ ๋‹ค๋ฅด๊ฒŒ ๋ณด์ด๊ฒŒ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

### ์˜ˆ์ƒ ๊ฐ’

Expand Down

0 comments on commit 1408129

Please sign in to comment.