Skip to content

fix #15#16

Closed
Sebastian-Nielsen wants to merge 2 commits intotapava:mainfrom
Sebastian-Nielsen:fix-15
Closed

fix #15#16
Sebastian-Nielsen wants to merge 2 commits intotapava:mainfrom
Sebastian-Nielsen:fix-15

Conversation

@Sebastian-Nielsen
Copy link
Copy Markdown

Havent manually tested it. The tests passes though.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 4, 2026

@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.

@tapava
Copy link
Copy Markdown
Owner

tapava commented Feb 6, 2026

@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.

@Sebastian-Nielsen
Copy link
Copy Markdown
Author

Sebastian-Nielsen commented Feb 6, 2026

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, globalThis.dayjs() works. But again, I dont want to pollute my main app's code with globalThis., so let's not go down that route.

I'll test this pr manually later today to confirm it solves my problem.

@tapava
Copy link
Copy Markdown
Owner

tapava commented Feb 6, 2026

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, globalThis.dayjs() works. But again, I dont want to pollute my main app's code with globalThis., so let's not go down that route.

I'll test this pr manually later today to confirm it solves my problem.

Totally makes sense. ComputeKit should handle this whether by:

  • Mapping external URLs to global names just like you did in this PR (remoteDependencyNames).
  • Or just pass the globals without URLs .. this can make it work with blob URLs also:
    remoteDependencyNames: ['dayjs', '_']

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>;
Copy link
Copy Markdown
Owner

@tapava tapava Feb 6, 2026

Choose a reason for hiding this comment

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

why not using an array of strings to simplify it ? we can also simplify the name to just 'globals'
globals?: string[];

@Sebastian-Nielsen
Copy link
Copy Markdown
Author

Sebastian-Nielsen commented Feb 6, 2026

This pr didnt solve it, I still get [ComputeKit:Pool:error] Task mlb80s2t-aizo5o8g9 failed: Ke is not defined

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

@tapava
Copy link
Copy Markdown
Owner

tapava commented Feb 6, 2026

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 .

@tapava tapava closed this Feb 6, 2026
@Sebastian-Nielsen
Copy link
Copy Markdown
Author

I know it pollutes the code but I don't think we have a better solution.

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.

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.

2 participants