Skip to content

fix(jsx): align link hoisting and dedupe with React 19#4792

Merged
yusukebe merged 5 commits intomainfrom
fix-hoisting-link-element-3
Mar 7, 2026
Merged

fix(jsx): align link hoisting and dedupe with React 19#4792
yusukebe merged 5 commits intomainfrom
fix-hoisting-link-element-3

Conversation

@usualoma
Copy link
Member

@usualoma usualoma commented Mar 5, 2026

fixes #4789

Summary

Because React 19 appears to dedupe only link elements that are stylesheet + precedence, this PR aligns Hono JSX runtime link hoisting/dedupe behavior with that model.

It fixes over-deduplication by href (for canonical / alternate / preload / icon / preconnect, etc.) and narrows dedupe to stylesheet links with precedence only.

As shown below, the list of links with issues reported in the issue will also remain without being deduplicated.

https://github.com/honojs/hono/compare/fix-hoisting-link-element-3?expand=1#diff-7077a729697655835dd10a0638c9e8ffaad5aef95597d9f409cc4e3f3fb9f848R374-R384

Compatibility

  • No public API or type changes.
  • Changes are limited to internal JSX runtime link hoisting/dedupe behavior and tests.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code

@usualoma
Copy link
Member Author

usualoma commented Mar 5, 2026

@yusukebe
Would you please review this?

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@usualoma
Copy link
Member Author

usualoma commented Mar 5, 2026

Oops

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@usualoma
Copy link
Member Author

usualoma commented Mar 5, 2026

@yusukebe
My bad. I've fixed it.

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 96.51163% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.58%. Comparing base (18cc595) to head (2b0d6d3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/jsx/dom/intrinsic-element/components.ts 94.11% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4792      +/-   ##
==========================================
+ Coverage   91.47%   91.58%   +0.10%     
==========================================
  Files         177      177              
  Lines       11578    11799     +221     
  Branches     3368     3458      +90     
==========================================
+ Hits        10591    10806     +215     
- Misses        986      992       +6     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

export const isStylesheetLinkWithPrecedence = (props: Props): boolean =>
props.rel === 'stylesheet' && 'precedence' in props

export const shouldDeDupeByKey = (tagName: string, props: Props, supportSort: boolean): boolean => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you apply the flowing patch to remove the lint error though CI does not fail?

diff --git a/src/jsx/intrinsic-element/common.ts b/src/jsx/intrinsic-element/common.ts
index aaa2ce0c..937c0974 100644
--- a/src/jsx/intrinsic-element/common.ts
+++ b/src/jsx/intrinsic-element/common.ts
@@ -15,7 +15,11 @@ export const dataPrecedenceAttr = 'data-precedence'
 export const isStylesheetLinkWithPrecedence = (props: Props): boolean =>
   props.rel === 'stylesheet' && 'precedence' in props

-export const shouldDeDupeByKey = (tagName: string, props: Props, supportSort: boolean): boolean => {
+export const shouldDeDupeByKey = (
+  tagName: string,
+  _props: Props,
+  supportSort: boolean
+): boolean => {
   if (tagName === 'link') {
     return supportSort
   }

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Bundle size check

main (5086956) #4792 (f61ef17) +/-
Bundle Size (B) 18,483B 18,483B 0B
Bundle Size (KB) 18.05K 18.05K 0K

Compiler Diagnostics (tsc)

main (5086956) #4792 (f61ef17) +/-
Files 303 303 0
Lines 141,272 141,272 0
Identifiers 129,303 129,303 0
Symbols 269,252 269,252 0
Types 198,829 198,829 0
Instantiations 614,273 614,273 0
Memory used 344,965K 328,528K -16,437K
I/O read 0.02s 0.03s 0.01s
I/O write 0s 0s 0s
Parse time 0.72s 0.68s -0.04s
Bind time 0.29s 0.29s 0s
Check time 2.47s 2.74s 0.27s
Emit time 0s 0s 0s
Total time 3.48s 3.71s 0.23s

Compiler Diagnostics (typescript-go)

main (5086956) #4792 (f61ef17) +/-
Files 303 303 0
Lines 145,453 145,453 0
Identifiers 130,894 130,894 0
Symbols 387,322 388,979 1,657
Types 366,137 366,137 0
Instantiations 988,802 988,802 0
Memory used 251,636K 252,199K 563K
Memory allocs 2,558,173 2,558,321 148
Config time 0.001s 0.001s 0s
Parse time 0.114s 0.117s 0.003s
Bind time 0.051s 0.052s 0.001s
Check time 0.818s 0.809s -0.009s
Emit time 0s 0s 0s
Total time 1.039s 1.029s -0.01s

Reported by octocov

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

HTTP Performance Benchmark

Framework Runtime Average Ping Query Body
hono (origin/main) bun 35,423.37 48,655.42 31,044.26 26,570.44
hono (current) bun 35,591.73 48,060.15 32,046.50 26,668.53
Change +0.48% -1.22% +3.23% +0.37%

@usualoma
Copy link
Member Author

usualoma commented Mar 6, 2026

@yusukebe
Fixed in 9d63042 and improved test coverage in 2b0d6d3.

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

yusukebe commented Mar 7, 2026

@usualoma

Thank you! Looks good.

@yusukebe yusukebe merged commit 8217d9e into main Mar 7, 2026
20 checks passed
@yusukebe yusukebe deleted the fix-hoisting-link-element-3 branch March 7, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

link rel=canonical is silently removed when it shares the same href as link rel=alternate hreflang

2 participants