UN-3185 [FIX] Restore global Prism for prismjs add-ons (Prompt Studio detail + HITL blank page)#2135
Conversation
… detail + HITL blank page) The Vite production build tree-shakes the bare `import "prismjs"` in CombinedOutput.jsx (a side-effect-only import with no used bindings), so nothing installs the global `Prism` that `prismjs/components/prism-json` and the line-numbers plugin reference. Those add-ons then throw `ReferenceError: Prism is not defined` at module evaluation, crashing the Combined Output viewer shared by the Prompt Studio detail page and the HITL / manual-review page (both render blank). The old CRA/webpack build did not tree-shake it, so the regression only surfaces on the Vite build. Add a dedicated prismSetup module that imports Prism core with a *used* binding (survives tree-shaking) and pins it on globalThis, and import it before the add-ons in CombinedOutput so the global is guaranteed present by the time the add-on modules evaluate. Verified against a production `vite build`: the emitted chunk now runs `globalThis.Prism = <core>` immediately before `Prism.languages.json = ...`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Summary by CodeRabbit
WalkthroughPrism is now initialized through a bootstrap helper that assigns the imported core to ChangesPrism Global Setup
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Drop the always-true `typeof globalThis !== "undefined"` check — globalThis is universally available in any ESM/Vite target. Addresses Greptile review. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…e (review) Address PR review: - silent-failure-hunter: a `!globalThis.Prism` guard could leave a different, pre-existing Prism in place, so the add-ons extend one instance while JsonView's highlightAll() reads another -> JSON silently unhighlighted. Assign unconditionally so the global is provably our core instance. - comment-analyzer: the prior comment blamed evaluation order yet relied on it to justify the fix. Rewrite: relying on prismjs core's self-install is unreliable under code-splitting; the explicit globalThis assignment (from first-party code imported before the add-ons) is the deterministic fix. Rebuilt: emitted chunk runs `globalThis.Prism = <core>` immediately before `Prism.languages.json = ...`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Verified against the actual on-prem image (built with the manual-review plugin): the per-component prismSetup import did NOT fix it. Because manual-review's ResultEditor also imports `prismjs/components/prism-json`, Rollup hoists that add-on into a SHARED lazy chunk (PdfViewer), separate from CombinedOutput's chunk where prismSetup ran — with no ordering guarantee between two lazy chunks, so the add-on still evaluated before the global was installed. My local OSS build masked this: with no manual-review plugin, prism-json wasn't shared and stayed in CombinedOutput's chunk. Fix: import prismSetup EAGERLY from index.jsx so `globalThis.Prism` is installed at bootstrap, before any lazy chunk (including the shared add-on chunk) can load. Robust regardless of how Rollup hoists prism-json. Reproduced the shared-chunk hoist locally (two independent lazy prism-json importers) and confirmed: prism-json lands in its own lazy chunk while globalThis.Prism stays in the eager entry <script type=module>, so the global is always installed first. Fixes both the Prompt Studio detail page and the HITL review page. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Frontend Lint Report (Biome)✅ All checks passed! No linting or formatting issues found. |
Update: moved the Prism global-install to the app entry (fixes HITL too)Testing the built on-prem image revealed the per-component
Fix (e0db7f3): import Verified in the built bundle: |
|



Problem
On the latest Vite build, the Prompt Studio detail page and the HITL / manual-review page render blank (ErrorBoundary fallback). Console shows:
Both pages share the Combined Output viewer (
CombinedOutput.jsx), which is where the crash originates.Root cause
CombinedOutput.jsxloads PrismJS language/plugin add-ons:prismjs/components/prism-json.jshas no imports — it references a free globalPrismand relies onimport "prismjs"having installed it first.import "prismjs"is a side-effect-only import with no used bindings, so the Vite/Rollup production build tree-shakes it away. Nothing installs the global, and the add-ons throwReferenceError: Prism is not definedat module evaluation, taking down the whole Combined Output subtree.Confirmed by inspecting the production bundle before this fix: the chunk runs
Prism.languages.json = {…}with nowindow.Prism/globalThis.Prismassignment anywhere in the output. The prism imports are unchanged since the initial commit — only the bundler (CRA/webpack → Vite) changed, which is why this only surfaces on the new build.Fix
frontend/src/helpers/prismSetup.js— imports Prism core with a used binding (tree-shake-proof) and pins it onglobalThis.CombinedOutput.jsx— importprismSetupbefore the add-ons so the global is guaranteed present when they evaluate. ESM evaluates a sibling dependency fully (body included) before the next, so ordering is guaranteed.Verification
Production
vite buildof the fixed tree — the emitted chunk now runs:i.e. the global is installed immediately before the add-on uses it. Build succeeds; no new warnings.
🤖 Generated with Claude Code