Copilot commented on code in PR #4997:
URL: https://github.com/apache/texera/pull/4997#discussion_r3212877946


##########
frontend/src/app/workspace/component/code-editor-dialog/code-debugger.component.ts:
##########
@@ -20,9 +20,6 @@
 import { AfterViewInit, Component, Input, ViewChild } from "@angular/core";
 import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
 import { SafeStyle } from "@angular/platform-browser";
-import "@codingame/monaco-vscode-python-default-extension";
-import "@codingame/monaco-vscode-r-default-extension";
-import "@codingame/monaco-vscode-java-default-extension";
 import { isDefined } from "../../../common/util/predicate";
 import * as monaco from "monaco-editor";
 import { MonacoBreakpoint } from "monaco-breakpoints";

Review Comment:
   `CodeDebuggerComponent` still has top-level side-effect imports of the 
codingame default extensions. Since this component is declared in `AppModule`, 
these imports will be evaluated on initial app load and can pull the heavy v25 
language extensions into the main bundle even if the code editor is never 
opened (defeating the lazy `ensureVscodeApiStarted()` activation flow). 
Consider removing these imports and relying on the centralized 
`ensureVscodeApiStarted()` (or a shared initializer) to load/activate 
extensions only when the editor stack is actually used.



##########
frontend/src/jsdom-svg-polyfill.ts:
##########
@@ -18,22 +18,49 @@
  */
 
 /**
- * jsdom doesn't implement the SVG geometry APIs 
(`SVGSVGElement#createSVGMatrix`,
- * `createSVGPoint`, `createSVGTransform`, `getScreenCTM`, `getCTM`,
- * `getBBox`). jointjs reaches into these during graph layout and crashes
- * the spec build with `TypeError: svgDocument.createSVGMatrix is not a
- * function` etc.
- *
- * The stubs below return identity-ish geometry: matrices/points behave like
- * the identity, bounding boxes report zero dimensions. That's enough for
- * jointjs construction code to not throw; specs that actually depend on
- * accurate geometry should run under Vitest browser mode rather than
- * jsdom (tracked in #4861), but the bulk of the texera specs only need
- * jointjs to instantiate cleanly.
+ * Test-environment polyfills + setup hooks for jsdom + the Angular
+ * `@angular/build:unit-test` builder. Pulled in via `setupFiles` in
+ * `angular.json`. Each block below targets a specific gap that surfaces
+ * when the codingame monaco-vscode-* v25 stack or jointjs runs under
+ * jsdom; comments next to each block say which one.
  */
 
+// ───────────────────────────────────────────────────────────────────────────
+// Node ESM loader hook so every transitive `.css` import resolves to an empty
+// module. The unit-test builder pre-bundles spec files with `externalPackages:
+// true`, so imports like `monaco-languageclient` reach Node's native ESM
+// loader instead of Vite's transform pipeline — without the hook, every spec
+// that transitively loads the codingame v25 stack crashes with
+// `Unknown file extension ".css"`. The hook source lives inline as a `data:`
+// URL so we don't carry a sidecar `.mjs`. Must run before any spec body
+// imports the affected packages; `module.register` needs Node 20.6+ (the
+// project pins Node ≥ 24).
+import { register as registerLoader } from "node:module";
+
+const cssLoaderHookSource = `
+export function resolve(specifier, context, nextResolve) {
+  if (specifier.endsWith(".css") || /\\.css(\\?|$)/.test(specifier)) {
+    return {
+      url: "data:text/javascript,export%20default%20%7B%7D%3B",
+      shortCircuit: true,
+      format: "module",
+    };
+  }
+  return nextResolve(specifier, context);
+}
+`;
+registerLoader(`data:text/javascript;charset=utf-8,${encodeURIComponent(cssLoaderHookSource)}`);
+
 type AnyFn = (...args: unknown[]) => unknown;
 
+// ───────────────────────────────────────────────────────────────────────────
+// SVG geometry APIs (`SVGSVGElement#createSVGMatrix`, `createSVGPoint`,
+// `createSVGTransform`, `getScreenCTM`, `getCTM`, `getBBox`). jsdom doesn't
+// implement these and jointjs reaches into them during graph layout, so the
+// spec build crashes with `TypeError: svgDocument.createSVGMatrix is not a
+// function`. Stubs below return identity-ish geometry — enough for jointjs
+// construction code not to throw. Specs needing accurate geometry should
+// run under Vitest browser mode rather than jsdom (tracked in #4861).
 function fakeMatrix() {

Review Comment:
   `src/jsdom-svg-polyfill.ts` is configured as a test `setupFiles` entry (runs 
once per spec file). Calling `module.register(...)` unconditionally will 
register a new ESM loader hook for every test file, which can lead to a growing 
hook chain and slower/less predictable module resolution across the run. 
Consider guarding this with a `globalThis` flag (register once per process) or 
moving the loader registration into a truly once-per-process setup path.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to