Skip to content

Bundler Fixes#23

Open
martindale wants to merge 5 commits into
feature/v0.2.0-RC3from
fix/bundler
Open

Bundler Fixes#23
martindale wants to merge 5 commits into
feature/v0.2.0-RC3from
fix/bundler

Conversation

@martindale
Copy link
Copy Markdown
Member

Fix the bundler.

cursor[bot]

This comment was marked as outdated.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Crypto Shim Fails Across Environments

The crypto-shim.js attempts to provide a synchronous Web Crypto API shim, but it is fundamentally flawed and incompatible across environments. Its digestSync implementation uses SharedArrayBuffer and Atomics.wait(). This approach is problematic in browsers because SharedArrayBuffer is often disabled or requires specific cross-origin isolation headers (e.g., COEP/COOP) due to security concerns (Spectre/Meltdown mitigations), and Atomics.wait() blocks the main thread, freezing the UI. Additionally, the shim mixes Node.js (Buffer) and browser (window) APIs, causing ReferenceError in Node.js (due to window access) or in browsers (due to Buffer usage without polyfill).

scripts/crypto-shim.js#L29-L84

data = combined;
} else if (Buffer.isBuffer(input)) {
const newData = new Uint8Array(input);
const combined = new Uint8Array(data.length + newData.length);
combined.set(data);
combined.set(newData, data.length);
data = combined;
} else {
throw new Error('Unsupported input type');
}
return this;
},
digest: function (encoding) {
const hash = window.crypto.subtle.digestSync(webCryptoAlgorithm, data);
const hashArray = Array.from(new Uint8Array(hash));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return encoding === 'hex' ? hashHex : Buffer.from(hashArray);
}
};
},
randomBytes: function (size) {
const array = new Uint8Array(size);
window.crypto.getRandomValues(array);
return Buffer.from(array);
}
};
// Add synchronous digest method to SubtleCrypto
window.crypto.subtle.digestSync = function (algorithm, data) {
// Create a synchronous version by using Atomics to wait for the async operation
const sharedArray = new SharedArrayBuffer(1);
const sharedInt32 = new Int32Array(sharedArray);
let result = null;
let error = null;
window.crypto.subtle.digest(algorithm, data)
.then(hashResult => {
result = new Uint8Array(hashResult);
Atomics.store(sharedInt32, 0, 1);
Atomics.notify(sharedInt32, 0);
})
.catch(err => {
error = err;
Atomics.store(sharedInt32, 0, 1);
Atomics.notify(sharedInt32, 0);
});
// Wait for the async operation to complete
Atomics.wait(sharedInt32, 0, 0);
if (error) {
throw error;
}
return result;
};

Fix in Cursor


Bug: Async Initialization and Incorrect Graphviz Option

The initializeGraph() method was changed to async but its callers are not updated to await it, potentially causing incomplete graph initialization. Furthermore, the graphviz instance loaded from @hpcc-js/wasm is incorrectly passed as a graphviz option to d3.select().graphviz(), which does not accept it, making the async loading ineffective.

components/GraphContent.js#L110-L125

async initializeGraph () {
if (!this.graphRef.current) return;
try {
const graphviz = await Graphviz.load();
const containerWidth = this.graphRef.current.parentElement.clientWidth;
this.graph = d3.select(this.graphRef.current).graphviz({
useWorker: false,
zoom: true,
fit: true,
width: containerWidth,
height: this.state.height,
engine: 'dot',
graphviz: graphviz
}).transition(() => {

Fix in Cursor


Bug: Duplicate Text in Paragraph

The paragraph under the "Fine-Tunable at Will" header contains duplicated text. The sentence "SENSEMAKER uses its entire history of interactions with the user to personalize each experience, typically leading to high-quality results from the processing pipeline." is copied from the preceding paragraph and appended without proper spacing or punctuation.

components/FeaturesHome.js#L58-L59

<Header>"Fine-Tunable" at Will</Header>
<p>As your relationship with SENSEMAKER grows, you are granted access to a database of "memories" that contribute to its personality. Modify, or remove, that information as you see fit — as we janitors like to say; garbage in, garbage out.SENSEMAKER uses its entire history of interactions with the user to personalize each experience, typically leading to high-quality results from the processing pipeline.</p>

Fix in Cursor


Bug: Crypto Hash Method Calls Undefined Function

The crypto.createHash().digest() method calls window.crypto.subtle.digestSync() before digestSync is defined and attached to window.crypto.subtle later in the same file, causing a runtime error. Additionally, the code lacks checks for the existence of window or window.crypto.subtle, leading to ReferenceError in Node.js or failures in environments without the Web Crypto API.

scripts/crypto-shim.js#L41-L42

digest: function (encoding) {
const hash = window.crypto.subtle.digestSync(webCryptoAlgorithm, data);

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant