microsoft / microsoft/monaco-editor

[Bug] Incorrect `[contenthash]` for filename for worker scripts from monaco-editor-webpack-plugin

Open
#3,615 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted open for PR webpack-plugin
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

No response

Monaco Editor Playground Code

No response

Reproduction Steps

No response

Actual (Problematic) Behavior

The monaco-editor-webpack-plugin uses loaderUtils.interpolateName to produce the file name for worker bundles:

https://github.com/microsoft/monaco-editor/blob/2b2e2a1eb793090ea4e91d2f6998ebeede9b6129/webpack-plugin/src/index.ts#L43-L51

The interpolateName function calculates the value of a [contentHash] placeholder in the provided string by hashing the contents of the contents value passed to it:

[contenthash] the hash of options.content (Buffer) (by default it's the hex digest of the xxhash64 hash)

In the code snippet above, this is fs.readFileSync(resolveMonacoPath(entry, monacoEditorPath)), which ends up loading something like monaco-editor/esm/vs/editor/editor.worker which is this file.

The issue here is that this file itself rarely changes which means that the [contenthash] value doesn't end up changing between releases even though it should.

For example, in a project we have using monaco, we upgraded to 0.35.0 recently, which contains meaningful changes in the worker. However, the [contenthash] value didn't change, so users who had previously loaded our project with an older version of monaco would continue to be served that older worker file via our caching rules.

Does the above make sense? Apologies if anything is misexplained, I haven't necessarily fully investigated how all the details of the webpack plugin work.

Expected Behavior

[contenthash] is a different value whenever anything in the worker bundle is different.

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in webpack-plugin/src/index.ts around lines 43-51 and read how loaderUtils.interpolateName receives the worker entry contents. Compare the generated filename hash across releases or worker bundles whose output changes. Done means [contenthash] changes whenever the worker bundle content changes, preventing stale cached worker files.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.