Skip to content

Commit cd297b5

Browse files
kubeclaude
andcommitted
H-5839: Bundle TypeScript into worker and remove CDN/polyfill workarounds
TypeScript now runs exclusively in the checker WebWorker, so: - Move `typescript` from main bundle externals into worker bundle - Add process/isNodeLikeSystem replacements to eliminate Node.js code paths - Remove Node.js polyfill fallbacks from next.config.js (fs, path, os, etc.) - Remove CDN CSP exceptions since Monaco is loaded locally Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bd51375 commit cd297b5

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

apps/hash-frontend/next.config.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,6 @@ export default withSentryConfig(
216216
// eslint-disable-next-line no-param-reassign
217217
webpackConfig.resolve.alias.canvas = false;
218218

219-
if (!isServer) {
220-
// Stub Node.js built-ins for browser — needed by `typescript` (used by
221-
// @hashintel/petrinaut's in-browser language service)
222-
// eslint-disable-next-line no-param-reassign
223-
webpackConfig.resolve.fallback = {
224-
...webpackConfig.resolve.fallback,
225-
module: false,
226-
fs: false,
227-
path: false,
228-
os: false,
229-
perf_hooks: false,
230-
};
231-
}
232-
233219
webpackConfig.plugins.push(
234220
new DefinePlugin({
235221
__SENTRY_DEBUG__: false,

apps/hash-frontend/src/lib/csp.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ export const buildCspHeader = (nonce: string): string => {
2424
"https://apis.google.com",
2525
// Vercel toolbar / live preview widget
2626
"https://vercel.live",
27-
// Monaco Editor loaded from CDN by @monaco-editor/react (used by petrinaut)
28-
"https://cdn.jsdelivr.net",
2927
],
3028

3129
"style-src": [
3230
"'self'",
3331
// Required for Emotion/MUI CSS-in-JS inline style injection.
3432
// @todo Use nonce-based approach via Emotion's cache `nonce` option.
3533
"'unsafe-inline'",
36-
// Monaco Editor stylesheet loaded from CDN by @monaco-editor/react (used by petrinaut)
37-
"https://cdn.jsdelivr.net",
3834
],
3935

4036
"img-src": [
@@ -49,11 +45,7 @@ export const buildCspHeader = (nonce: string): string => {
4945
...(process.env.NODE_ENV === "development" ? ["http:"] : []),
5046
],
5147

52-
"font-src": [
53-
"'self'",
54-
// Monaco Editor CSS embeds the Codicon icon font as an inline base64 data URI
55-
"data:",
56-
],
48+
"font-src": ["'self'"],
5749

5850
"connect-src": [
5951
"'self'",

libs/@hashintel/petrinaut/vite.config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default defineConfig({
2121
"react",
2222
"react-dom",
2323
"reactflow",
24-
"typescript",
2524
"monaco-editor",
2625
"@babel/standalone",
2726
],
@@ -48,7 +47,17 @@ export default defineConfig({
4847
// This causes crashes in Web Workers, since `window` is not defined there.
4948
// To prevent this, we do this resolution on our side.
5049
"typeof window": '"undefined"',
50+
// TypeScript's internals reference process, process.versions.pnp, etc.
51+
"typeof process": "'undefined'",
52+
"typeof process.versions.pnp": "'undefined'",
5153
}),
54+
// Separate replacePlugin for call-expression replacements:
55+
// 1. Empty end delimiter because \b can't match after `)` (non-word → non-word).
56+
// 2. Negative lookbehind skips the function definition (`function isNodeLikeSystem`).
57+
replacePlugin(
58+
{ "isNodeLikeSystem()": "false" },
59+
{ delimiters: ["(?<!function )\\b", ""] },
60+
),
5261
],
5362
},
5463

@@ -59,6 +68,7 @@ export default defineConfig({
5968
"react/compiler-runtime",
6069
"react/jsx-runtime",
6170
"react/jsx-dev-runtime",
71+
"typescript",
6272
],
6373
}),
6474

0 commit comments

Comments
 (0)