Automattic / Automattic/harper
Harper-JS (<= v2.7.0) loading standard WASM variant attempts to load load slim WASM variant
- Dominant language
- Rust
- Stars
- 15.4k
- Forks
- 627
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 106
Description
**Describe the bug**
When importing the full WASM binary only via harper.js/binary from the distribution directory in +v2.4.0 versions, Harper attempts to fetch harper_wasm_slim_bg.wasm file. The request seems to be fired unconditionally, resulting in a 404 in the network log. As I personally don't the reason to have the full variant and slim variant when they are almost the same size.
I have not uploaded the complete dist folder into my project as I would like to keep the size impact as small as possible due to the platform that I am using best practices.
**To Reproduce**
(Not exactly the code I am running but it covers the steps)
```javascript
(function initHarper() {
const baseUrl = '/harper_2.7.0';
const harperUrl = `${baseUrl}/harper.js`;
const binaryUrl = `${baseUrl}/binary.js`;
const harperConfig = JSON.parse($parameters.Config);
if(!window._harperLoaded) {
window._harperLoaded = new Promise(function (resolve,reject) {
const script = document.createElement("script");
script.type = "module";
script.textContent = `
import { WorkerLinter, Dialect } from "${harperUrl}";
import { binary } from "${binaryUrl}";
try {
const linter = new WorkerLinter ({
binary,
dialect: Dialect.British
});
window.linter = linter;
window.dispatchEvent(new CustomEvent("HarperLoaded"));
} catch (err) {
console.error("Failed to load Harper module script",err);
window.dispatchEvent(new CustomEvent("HarperError", {
detail: String(err)
}));
}
`;
document.head.appendChild(script);
});
}
})();
```
The only files I've uploaded are:
- binary.js
- harper.js
- harper_wasm_bg.wasm
- BinaryModule-Aj1vLnwf.js (v2.7.0)
These files seem to be the mininum necessary files to run the standard/full variant of Harper-JS as my integration works as expected besides that 404 error in the network logs
**Expected behavior**
No attempted loading of any slim variant assets.
**Platform**
Harper-JS in a OutSystems Personal Environment (OutSystems 11)
**Additional context**
**DISCLAIMER**: The following section is AI Agent generated as I pulled those files I have in my project and explained my issue to see if it would pick up anything obvious. Since I am not fully contextualised on how the project is layed out I'll like to leave this here in the hopes that it would save someone with better understanding some time.
- This is in the compiled glue code (`BinaryModule-Aj1vLnwf.js`), specifically in `getDefaultGlueBinary()`:
```javascript
function getDefaultGlueBinary(binary, glueFlavor) {
if (glueFlavor === "slim") return binary;
if (binary.includes("harper_wasm_bg.wasm")) {
return binary.replace("harper_wasm_bg.wasm", "harper_wasm_slim_bg.wasm");
}
return null;
}
```
- When `glueFlavor` is `"full"` and the binary URL contains `harper_wasm_bg.wasm`, it unconditionally constructs a slim URL — regardless of whether that file actually exists.
- `loadBinaryUncached()` then calls `__wbg_init$1` with this slim URL. For the full flavor, errors are silently caught (line 3052-3056), but the HTTP request still fires.
- The npm package **does** ship `binary_slim.js` and `harper_wasm_slim_bg.wasm` separately, but consumers using only the full binary have no reason to download or serve the slim variant.
Contributor guide
Research direction
Start in BinaryModule-Aj1vLnwf.js at getDefaultGlueBinary() and loadBinaryUncached(), then reproduce the harper.js/binary import using only the four listed assets. Done means the full variant still loads and no request is made for harper_wasm_slim_bg.wasm.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, rust, wasm
- Domain
- tooling, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100