fix #15#16
Conversation
|
@Sebastian-Nielsen is attempting to deploy a commit to the ghassen ben hadj lassoued's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Sebastian-Nielsen Thanks. Let's see if there is a way to access globals by simply using self. I will test it on a production env. Will also take a look at your fix. |
Even if there were that is not a good solution since, ideally, it should be possible to reuse util methods from your app in webworkers. Whatever method you discover you would then polute the util methods of your app with that hack. We should have a fix like I proposed in this pr. By the way, I'll test this pr manually later today to confirm it solves my problem. |
Totally makes sense. ComputeKit should handle this whether by:
Another thing I want to test is how will this work in case of name collision .. if I use two external deps URLs that expose the same function (e.g dayjs in dayjs/1.11.18/dayjs.min.js and then again dayjs in dayjs/1.2.0/dayjs.min.js) We should probably add this validation to make sure no duplicate globals are being used. |
| /** Remote scripts to load in workers via importScripts */ | ||
| remoteDependencies?: string[]; | ||
| /** Maps remote dependency URLs to their global variable names (useful for handling obfuscation in production builds) */ | ||
| remoteDependencyNames?: Record<string, string>; |
There was a problem hiding this comment.
why not using an array of strings to simplify it ? we can also simplify the name to just 'globals'
globals?: string[];
|
This pr didnt solve it, I still get A snippet from my compiled code: self.D8 = function D8(e) {
const n = e.evaluations.map(t => _0(t));
return {
...e,
evaluations: n,
procedureDatetime: Ke(e.procedureDatetime) // `Ke` is `dayjs` in my original code
}
}I tested it like this: const workerUtilsCode = `
self.${getIsoDateRegex.name} = ${getIsoDateRegex.toString()};
self.${replacer.name} = ${replacer.toString()};
// ...
`;
export const kit = new ComputeKit({
remoteDependencies: [
"https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.18/dayjs.min.js",
workerUtilsUrl,
],
remoteDependencyNames: {
'https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.18/dayjs.min.js': 'dayjs',
}
}).register(...);https://www.npmjs.com/package/@sebastian-nielsen-computekit/core |
|
hmm, It looks like the only options are using self.dayjs() or thisGlobal.dayjs(). Both should work. I know it pollutes the code but I don't think we have a better solution. Closing the PR but I'll keep the issue for a while in case we needed to discuss alternatives . |
There is likely a proper solution—comlink managed to solve this—but I don’t have the time to investigate further right now, so I’ll migrate to Comlink for now. |
Havent manually tested it. The tests passes though.