Yicong-Huang commented on PR #4997:
URL: https://github.com/apache/texera/pull/4997#issuecomment-4883941326

   Tracked down the broken syntax highlighting / `cmd+/` / theme CSS from my 
comment above. Root cause is in the webpack build path.
   
   ### Root cause
   
   `ng serve` and `yarn build` go through webpack 
(`@angular-builders/custom-webpack`), where Angular's base config sets 
`module.parser.javascript.url: false` and `worker: false` (no 
`webWorkerTsConfig` in angular.json). With both off, webpack leaves `new 
URL(..., import.meta.url)` untransformed and inlines `import.meta.url` as a 
**build-machine `file://` path**. From the actual dev-server compiled output:
   
   ```js
   fetch(new 
URL('../../../../../../../external/vscode-oniguruma/release/onig.wasm',
     
"file:///Users/.../node_modules/@codingame/monaco-vscode-textmate-service-override/..."))
   
   new Worker(new URL("./workers/editor.worker",
     
"file:///Users/.../src/app/workspace/component/code-editor-dialog/code-editor.component.ts"))
   ```
   
   In a real browser both fail: the onig.wasm fetch dies → the TextMate 
tokenizer never starts → no Python/Java highlighting; all three worker 
trampolines fail to spawn → language configuration and theming degrade (`cmd+/` 
dead, unreadable token colors).
   
   This PR removed the previous `parser: { javascript: { url: true } }` 
override in `custom-webpack.config.js` — it was there precisely for the wasm 
case (see 
[angular-cli#24617](https://github.com/angular/angular-cli/issues/24617)) — and 
`worker` parsing has never been enabled in the webpack builds.
   
   ### Why CI stayed green
   
   The vitest specs (including the browser-mode ones) run through esbuild 
(`@angular/build:unit-test`), which natively supports both `new URL(...)` 
assets and `new Worker(new URL(...))`. Only the webpack-based `ng serve` / 
`yarn build` are affected — so every test passes while the served app is 
broken. The "worker chunks identical hashes/sizes" note in the PR description 
is worth re-checking: with `parser.javascript.worker: false`, webpack cannot 
have emitted those chunks.
   
   ### Fix (verified against the dev-server output)
   
   Restore/extend the parser override in `frontend/custom-webpack.config.js`:
   
   ```js
   module: {
     rules: [ /* unchanged */ ],
     parser: {
       javascript: {
         url: true,    // onig.wasm is fetched via new URL(..., import.meta.url)
         worker: true, // bundle the ./workers/* trampolines as worker chunks
       },
     },
   },
   ```
   
   With this applied, the compiled output contains zero `file://` references; 
onig.wasm is emitted as a hashed asset (466 KB, served 200) and the three 
trampolines become real worker chunks (editor 384 KB, extension-host 4.4 MB, 
textmate 107 KB).
   
   One gotcha for anyone re-testing: webpack's persistent cache 
(`.angular/cache`) does **not** track `custom-webpack.config.js`, so clear it 
before restarting `ng serve` — otherwise the stale broken output keeps being 
served.
   


-- 
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