LibreChat/client/src/lib/sandpack.ts
lia-by-librechat[bot] 93f0563153
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Backend Unit Tests / backend (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Frontend Unit Tests / frontend (push) Blocked by required conditions
Playwright E2E Tests / Codegraph select (push) Waiting to run
Playwright E2E Tests / e2e () (push) Blocked by required conditions
Playwright E2E Tests / MCP list_changed (replica count 1) (push) Blocked by required conditions
Playwright E2E Tests / MCP list_changed (replica count 2) (push) Blocked by required conditions
Playwright E2E Tests / MCP Apps (browser and server) (push) Waiting to run
Playwright E2E Tests / e2e (push) Blocked by required conditions
🛖 fix: Isolate Sandpack Console Globals From HTML Artifacts (#18093)
Co-authored-by: Lia <lia@librechat.ai>
2026-11-12 11:42:03 -05:00

26 lines
1.2 KiB
TypeScript

import type { Plugin } from 'vite';
const injection = String.raw`var scriptToInsert = "\n <script>\n const scope = ".concat(JSON.stringify(scope), ";\n ").concat(script, "\n </script>\n ").trim();`;
const scopedInjection = String.raw`var scriptToInsert = "\n <script>\n (function () {\n const scope = ".concat(JSON.stringify(scope), ";\n ").concat(script, "\n })();\n </script>\n ").trim();`;
/** Sandpack 2.19.8 leaks console-hook bindings into the artifact's global scope. */
export function sandpackConsoleIsolation() {
return {
name: 'sandpack-console-isolation',
transform: {
filter: {
id: /[\\/]node_modules[\\/]@codesandbox[\\/]sandpack-client[\\/]dist[\\/]index-[^\\/]+\.(?:mjs|js)(?:\?|$)/,
},
handler(code: string) {
if (!code.includes('SandpackStatic.prototype.injectScriptIntoHead')) {
return null;
}
// Fail on dependency drift instead of silently restoring collisions.
if (code.split(injection).length !== 2) {
throw new Error('Sandpack static script injection changed; update console isolation.');
}
return { code: code.replace(injection, scopedInjection), map: null };
},
},
} satisfies Plugin;
}