Skip to content
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

fix(clerk-js): Bundle the zxcvbn library inside the headless variant #3038

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

anagstef
Copy link
Member

Description

Currently, the zxcvbn is lazy loaded on clerk-js due to its size. However, using import() is not working in non-browser environments, including Expo.

Considering the assumption that the clerk.headless.js variant is only used on native environments, this PR bundles the whole zxcvbn inside the headless clerk-js.

This PR will fix the usage of the validatePassword on Expo.

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Mar 22, 2024

🦋 Changeset detected

Latest commit: b3e55f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@BRKalow
Copy link
Member

BRKalow commented Mar 22, 2024

@anagstef Let's add an e2e here that uses the headless entry and calls validatePassword() 👀

@panteliselef
Copy link
Member

@anagstef I think we should also mention the increase in the bundle size as it is significant.

@anagstef
Copy link
Member Author

@anagstef Let's add an e2e here that uses the headless entry and calls validatePassword() 👀

@BRKalow we should find a way to mimic the non-browser environment. We should give a shot to https://wix.github.io/Detox/

@anagstef I think we should also mention the increase in the bundle size as it is significant.

@panteliselef you mean on the changeset?

Comment on lines 158 to 160
new webpack.DefinePlugin({
__IS_BROWSER__: variant !== variants.clerkHeadless,
}),
Copy link
Member

Choose a reason for hiding this comment

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

My understanding is that this is only used in clerkHeadless package, so let's kill the variant argument from here and move the plugin definition to the clerkHeadless rules in prodConfig (probably line 196?)

let core;
let languageCommon;
if (__IS_BROWSER__) {
core = import('@zxcvbn-ts/core');
Copy link
Member

Choose a reason for hiding this comment

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

❓ Is this a sync import?
Pretty sure this is not widely supported yet - this should probably be awaited here.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a webpack config we can leverage where dynamic imports are "ignored" and instead they are bundled as normal?

Copy link
Member Author

@anagstef anagstef Mar 29, 2024

Choose a reason for hiding this comment

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

Is this a sync import?

This is followed by:

return Promise.all([core, languageCommon]);

so, we don't expect it to be sync.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a webpack config we can leverage where dynamic imports are "ignored" and instead they are bundled as normal?

Didn't find anything. :(

@anagstef anagstef force-pushed the stefanos/sdk-1545-validatepassword-throws-error-on-expo branch from 00b4f82 to 404a197 Compare March 29, 2024 12:08
Comment on lines 26 to 27
core = await require('@zxcvbn-ts/core');
languageCommon = await require('@zxcvbn-ts/language-common');
Copy link
Member

Choose a reason for hiding this comment

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

Isn't require synchronous ?

Copy link
Member

@LekoArts LekoArts Apr 2, 2024

Choose a reason for hiding this comment

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

@anagstef I also think that the await before the require isn't doing anything

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I've removed this, but haven't pushed yet! Thank you both for noticing!

Comment on lines 29 to 32
core = await import('@zxcvbn-ts/core');
languageCommon = await import('@zxcvbn-ts/language-common');
}
return Promise.all([core, languageCommon]);
return { core, languageCommon };
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean the the dependencies will no longer load in parallel ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. Nice catch! I'll revert this one.

@nikosdouvlis
Copy link
Member

@anagstef do we have any updates on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants