perf(link): skip reactivity when rendering on the server - #2774
Conversation
✅ Deploy Preview for vue-router canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRouterLink now shares route and navigation helpers between client and SSR paths. SSR rendering resolves links synchronously without reactive setup. New tests cover link states, classes, slots, aliases, parameters, custom links, and browser-mode parity. ChangesRouterLink SSR support
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant VueSSRRenderer
participant RouterLink
participant Router
VueSSRRenderer->>RouterLink: Render RouterLink
RouterLink->>Router: Resolve route and active state
Router-->>RouterLink: Return href and navigation state
RouterLink-->>VueSSRRenderer: Render anchor or custom link
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2774 +/- ##
==========================================
+ Coverage 86.99% 87.08% +0.08%
==========================================
Files 93 93
Lines 10722 10785 +63
Branches 2478 2490 +12
==========================================
+ Hits 9328 9392 +64
Misses 1388 1388
+ Partials 6 5 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
If this applies to all computed, maybe we could directly apply the improvement to vue. What do you think? We could also create an SSR RouterLink that only renders an |
|
the speedup is largely from avoiding allocating the computed at all (e.g. no arrow function, no proxies), so I'm not sure we can achieve that in Vue itself. |
|
I see. Let's hold on for the moment on this one: I'm not sure the added size and complexity here is worth it |
Note
spotted when doing some benchmarking of
<NuxtLink>that there was an opportunity to speed up rendering<RouterLink>for SSR.on the server a
<RouterLink>doesn't need to be reactive, but five computed values are produced byreactive(useLink(props)), which has a cost which we can avoidto avoid two copies of most of the logic, this moves most computed values into plain functions which can be directly executed in the SSR fast-path, or built into computed values for client-side state.
I've done benchmarking locally using 200 links with
renderToString(note that the mean value here is inflated by GC so the min value is truer unless using with lots of links)<a>my tentative headline is that renders
<RouterLink>in server environments ~1.5-2.2x faster. per link that's still tiny: 4.55 μs -> 2.08 μs, but every little helps, right?(you'll probably want to run your own numbers but I'd be very happy to share my benchmark script if that helps)
let me know if I've missed anything, or you think this is the wrong approach. we can also resolve this in nuxt separately but thought this would be useful to upstream.
Summary by CodeRabbit
Bug Fixes
Tests