Conversation
WalkthroughAdds a Furion SDK injector and invokes it from the VitePress theme's enhanceApp hook so the SDK script is dynamically appended and configured during app initialization. Changes
Sequence Diagram(s)sequenceDiagram
participant App as VitePress Theme (enhanceApp)
participant Browser as Browser Runtime
participant Window as window
participant CDN as Furion CDN (https://res.hc-cdn.com)
App->>Browser: call insertFurion()
Browser->>Window: set __fr.config (appId, setting, hashMode, smartJsErr)
Browser->>CDN: create <script src=".../furion-cdn.min.js">
Browser->>Browser: append script to document.body
CDN-->>Browser: load & execute Furion SDK
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.vitepress/theme/insert-furion.ts:
- Around line 2-16: The insertFurion function currently accesses window and
document unguarded which breaks VitePress SSR; modify insertFurion to first
check for a browser environment (e.g. typeof window !== 'undefined' && typeof
document !== 'undefined') and return early if false, and only run the IIFE that
references window[n], document.createElement, document.body, insertBefore, etc.,
when the guard passes so no server-side ReferenceError occurs.
🧹 Nitpick comments (3)
.vitepress/theme/insert-furion.ts (3)
6-6: HardcodedappIdshould be externalized.Embedding the monitoring app ID directly in source code makes it harder to manage across environments (dev/staging/prod) and exposes the identifier in the public repository. Consider using a VitePress environment variable (e.g.,
import.meta.env.VITE_FURION_APP_ID).
1-1: Prefer proper typing over@ts-ignore.You can augment the
Windowinterface instead of suppressing the type error:declare global { interface Window { __fr: { config?: Record<string, unknown> } } }This gives you type safety on
window.__frwithout needing the ignore directive.
3-16: No guard against duplicate script injection.If
insertFurionis called more than once (e.g., during HMR), a duplicate<script>tag will be appended. Consider adding an idempotency check.♻️ Example idempotency guard
export function insertFurion() { if (typeof window === 'undefined') return + if (document.querySelector('script[data-furion]')) return !(function (x: string, n: string) { ... let o = document.createElement('script') + o.setAttribute('data-furion', '') o.src = x
Summary by CodeRabbit