Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "prismjs";
// global Prism is installed eagerly at app entry (helpers/prismSetup.js)
import "prismjs/components/prism-json";
import "prismjs/plugins/line-numbers/prism-line-numbers.css";
import "prismjs/plugins/line-numbers/prism-line-numbers.js";
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/helpers/prismSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Prism from "prismjs";

// The prismjs language/plugin add-ons used across the app (`prismjs/components/*`,
// `prismjs/plugins/*`) register their grammars onto a *bare global* `Prism` and
// carry no import edge back to prismjs core. Under Vite's code-split production
// build those add-ons get hoisted into a shared chunk (Combined Output *and* the
// manual-review ResultEditor both import `prism-json`), which can evaluate before
// any per-component setup runs — so they threw `ReferenceError: Prism is not
// defined`, blanking the Prompt Studio detail page and the HITL review page.
//
// This module is imported EAGERLY from the app entry (`index.jsx`) so the global
// is installed at bootstrap, before any lazy chunk — including the shared one
// holding the add-ons — can load. Assign unconditionally: the global must be THIS
// instance, the one the add-ons extend and that `Prism.highlightAll()` reads; a
// `!globalThis.Prism` guard could leave a different, pre-existing Prism in place
// and silently drop highlighting. The used `Prism` binding also keeps the bundler
// from tree-shaking core away.
globalThis.Prism = Prism;

export default Prism;
3 changes: 3 additions & 0 deletions frontend/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Install the global `Prism` at bootstrap, before any lazy chunk (incl. the
// shared one holding prismjs add-ons) can load. See helpers/prismSetup.js.
import "./helpers/prismSetup";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import React from "react";
Expand Down