fix(core): load Osano consent script async via client module#262
fix(core): load Osano consent script async via client module#262marythought wants to merge 9 commits intomainfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRemoved the inline Osano CMP script from Docusaurus config, added a client module that injects the Osano script and exposes Changes
Sequence Diagram(s)sequenceDiagram
participant Browser as Browser (Client)
participant Loader as OsanoLoader (clientModule)
participant Head as DocumentHead (DOM)
participant Osano as OsanoCMP (External Script)
rect rgba(200,230,255,0.5)
Browser->>Loader: page loads (DOM available)
Loader->>Head: check for existing Osano script
alt script missing
Loader->>Head: append async `<script src="https://cmp.osano.com/.../osano.js">`
end
end
rect rgba(200,255,200,0.5)
Note over Osano,Browser: External script downloads & initializes asynchronously
Osano-->>Browser: exposes `window.Osano.cm.showDrawer`
Loader->>Browser: set `window.openOsanoPreferences()` (calls Osano when available)
end
rect rgba(255,230,200,0.5)
Browser->>Browser: user clicks "Preferences"
Browser->>Loader: invokes `window.openOsanoPreferences()`
Loader->>Osano: calls `window.Osano?.cm?.showDrawer?.('osano-cm-dom-info-dialog-open')`
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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)
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.
Code Review
This pull request refactors the Osano script loading by moving it from a static script tag in docusaurus.config.ts to a dynamic loader in a new client module, src/theme/OsanoLoader.js. A review comment suggests extracting the hardcoded script URL into a constant to improve maintainability.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/theme/OsanoLoader.js`:
- Around line 3-9: The Osano script loader in OsanoLoader.js appends the script
unconditionally causing duplicate injection and race errors when footer onclick
calls Osano.cm.showDrawer; update the loader to first check
document.querySelector for the Osano script src or an id before
creating/appending the script, attach script.onerror to log/handle load
failures, and expose a safe wrapper function window.openOsanoPreferences() that
calls window.Osano?.cm?.showDrawer(...) with optional chaining to avoid
exceptions if the script hasn’t loaded yet; finally change footer invocation to
call window.openOsanoPreferences() instead of Osano.cm.showDrawer().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 16f21428-cd35-42e3-8f8b-d855cf7dda91
📒 Files selected for processing (2)
docusaurus.config.tssrc/theme/OsanoLoader.js
|
📄 Preview deployed to https://opentdf-docs-pr-262.surge.sh |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/surge-preview.yaml:
- Around line 43-45: Add the same SPA fallback step used in the surge-preview
workflow to the manual deployment workflow by inserting a step that runs the
command `cp build/index.html build/200.html` after the build step in
surge-preview-deploy.yaml (mirror the behavior of the existing "Add SPA fallback
for Surge" step) so manual deployments also serve 200.html for client-side
routes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 19cccb46-d322-4f8e-9c78-97321a15a324
📒 Files selected for processing (1)
.github/workflows/surge-preview.yaml
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docusaurus.config.ts`:
- Line 236: The footer button currently calls window.openOsanoPreferences
directly causing a ReferenceError during SSR or before client hydration; change
the onclick to safely guard the call (e.g., check typeof
window.openOsanoPreferences === 'function' before invoking) or remove the inline
onclick and wire the click handler from the client-side OsanoLoader
initialization so clicks before hydration no-op; update the element that renders
the button to use the guarded call (reference: window.openOsanoPreferences and
the client module OsanoLoader.js) so the handler degrades gracefully when the
client module hasn't loaded yet.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dd8b6dcf-8324-4559-9463-587e95711f89
📒 Files selected for processing (1)
docusaurus.config.ts
The synchronous Osano CMP script in headTags blocks Docusaurus client-side hydration when the consent service is unreachable (local dev, surge previews), breaking interactive components like tabs. Docusaurus strips the async attribute from headTags script elements, so we load Osano via a client module instead, which runs after hydration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Surge requires a 200.html file to handle client-side routing fallback. Without it, Docusaurus SPA navigation breaks when navigating between doc sections (e.g., Components → SDKs) because Surge returns a 404 for routes not matching a static file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Matches the same 200.html fallback added to the auto-deploy workflow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… errors - Extract URL into constant and check for existing script before appending - Add safe wrapper window.openOsanoPreferences() with optional chaining - Update footer onclick to use wrapper instead of calling Osano.cm directly Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds script.onerror handler to log a warning if the Osano CMP script fails to load, addressing CodeRabbit review feedback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Osano CMP script blocks page loading when cmp.osano.com is unreachable or slow (localhost, some preview environments), breaking React hydration and client-side navigation. Gate the script injection on hostname so it only loads in production and deployed previews. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace localhost exclusion with a production hostname allowlist (OSANO_HOSTS). Osano only loads on opentdf.io — skipped on localhost, Surge previews, and any other non-production environment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ca6d298 to
beebbb2
Compare
Use optional chaining on the onclick handler so pre-hydration clicks degrade silently instead of throwing a ReferenceError. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
headTagsto a Docusaurus client module (src/theme/OsanoLoader.js)opentdf.io) via an allowlist — skipped on localhost, Surge previews, and all other non-production environmentsquerySelectorguard against duplicate injection,script.onerrorhandler, and safewindow.openOsanoPreferences()wrapper with pre-hydration guard200.htmlSPA fallback in Surge preview workflowsRoot Cause
Docusaurus strips the
asyncattribute fromheadTagsscript elements. The Osano CMP script blocks page loading whencmp.osano.comis slow or unreachable — preventing React hydration, chunk loading, and all client-side navigation. Even loading async viaappendChildin a client module still blocks when the CDN is unreachable.Confirmed by systematic bisect (2026-04-03):
13d5235)Changes
docusaurus.config.ts: Remove Osano fromheadTags, registerOsanoLoader.jsas client module, update footer to usewindow.openOsanoPreferences?.()(safe before hydration)src/theme/OsanoLoader.js: New client module — injects Osano only onOSANO_HOSTS(opentdf.io,www.opentdf.io), exposes safe preferences wrapper everywhere.github/workflows/surge-preview.yaml,surge-preview-deploy.yaml: Add200.htmlSPA fallback for SurgeTest plan
npm start)npm run buildsucceeds🤖 Generated with Claude Code