-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
detChoice problems in browser #48
Comments
Thanks for the report! That's the right usage (assuming author.address is a string). earthstar/src/util/detRandom.ts Lines 43 to 45 in e0eb930
earthstar/src/util/detRandom.ts Lines 24 to 33 in e0eb930
...I haven't tested this in the browser yet. Since the error is coming from How are you bundling this, is it browserify or webpack? Can you get a more detailed traceback? SpeedIt should be very fast to run once, the problem is running it for every rendered React component over and over. Faster hash functionWe should switch from sha256 to md5 or something even faster. This isn't security critical. Wait for sodium to load WASMInvestigate this note about waiting for sodium to load its WASM module. Is the slowness only temporary until WASM is loaded, or does it get stuck with the slow version if we use it without waiting? MemoizeMemoizing / caching the function should fix it, but it will still be slow on the first render. Something like: let colorCache = {} // mapping from author address to color string
let authorToColor(author: string): string => {
if (colorCache[author]) { return colorCache[author]; }
let color = detRandom(author, ['red', 'green', 'blue']);
colorCache[author] = color;
// todo: if cache is getting too big, randomly delete an item here
return color;
} |
This reminds me about #2 Make Tests Run In Browsers ;) If you have experience with that, I'd appreciate help. |
I verified that I'm guessing this error happened in earthstar-lobby which uses Webpack (via TheoryMaybe Webpack doesn't bundle
I'm not sure how everything could have worked so far but broken when earthstar/src/util/detRandom.ts Line 30 in e0eb930
Webpack uses a pretty old polyfill, If this theory is true, all of the Other theoryBack over here in // we need to skip all the sqlite-related code when bundling for the browser
"browser": {
"./build/index.js": "./build/index.browser.js", // swap out index for a version that doesn't import sqlite
"./build/storeSqlite.js": false, // skip the other file that imports sqlite
"tap": "tape" // use a browser-compatible test module
}, I can't figure out if Webpack understands this "browser": "./build/index.browser.js", ??? |
I published earthstar I just copy-pasted node's code for If it doesn't work can you point me to a commit in earthstar-lobby that triggers the error? |
Closing this for now since it seems to not be an issue lately. Please re-open if it can be reproduced. |
Peer syncing: add AllStorageStates API and tests
What's the problem you want solved?
This usage of
detChoice
:Results in the following error:
Am I using it wrong somehow?
And: is this function meant to be used in the browser? Calling it in a client gives me warning messages about how resource-hungry the current tab is.
The text was updated successfully, but these errors were encountered: