crossmint-sdk icon indicating copy to clipboard operation
crossmint-sdk copied to clipboard

infra: make most pkgs tree shakable

Open mPaella opened this issue 1 year ago • 13 comments

Description

making most of the packages tree shakable

Test plan

u can see the bundle sizes of our apps has been decreased (new is on the right) image

tested payments demo nextjs app

mPaella avatar Sep 26 '24 17:09 mPaella

⚠️ No Changeset found

Latest commit: 77ba139c6247b02dfcad58b0319a3c1529a8d508

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

changeset-bot[bot] avatar Sep 26 '24 17:09 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
smart-wallet-auth-demo ⬜️ Ignored (Inspect) Visit Preview Sep 27, 2024 3:59pm

vercel[bot] avatar Sep 26 '24 17:09 vercel[bot]

If the config is the same, would it be possible to have one in the root and import it from each package?

AlbertoElias avatar Sep 26 '24 18:09 AlbertoElias

For @AlbertoElias to consider during review -- is this test plan sufficient? Could tree-shaking fail in unexpected ways we must test? (e.g. run a couple demo sites or something)

alfonso-paella avatar Sep 26 '24 18:09 alfonso-paella

If the config is the same, would it be possible to have one in the root and import it from each package?

done

mPaella avatar Sep 26 '24 19:09 mPaella

I'm testing it with other apps. So far, in Smarter Wallet, there are some styles that are not being built correctly so I'm looking into it.

@jmderby could you chime in with how twind works to create classes on the fly? The issue comes with classes that are set conditionally during execution such as:

<iframe
    ref={iframeRef}
    src={iframeSrc}
    onLoad={handleIframeLoaded}
    title="Authentication Modal"
    className={classNames(
        "w-full h-[500px] border pt-12 pb-8",
        appearance?.colors?.border
            ? `border-[${appearance.colors.border}]`
            : "border-[#D0D5DD]",
        appearance?.borderRadius ? `rounded-[${appearance.borderRadius}]` : "rounded-2xl",
        appearance?.colors?.background ? `bg-[${appearance.colors.background}]` : "bg-white"
    )}
/>

AlbertoElias avatar Sep 27 '24 12:09 AlbertoElias

I'm testing it with other apps. So far, in Smarter Wallet, there are some styles that are not being built correctly so I'm looking into it.

@jmderby could you chime in with how twind works to create classes on the fly? The issue comes with classes that are set conditionally during execution such as:

<iframe
    ref={iframeRef}
    src={iframeSrc}
    onLoad={handleIframeLoaded}
    title="Authentication Modal"
    className={classNames(
        "w-full h-[500px] border pt-12 pb-8",
        appearance?.colors?.border
            ? `border-[${appearance.colors.border}]`
            : "border-[#D0D5DD]",
        appearance?.borderRadius ? `rounded-[${appearance.borderRadius}]` : "rounded-2xl",
        appearance?.colors?.background ? `bg-[${appearance.colors.background}]` : "bg-white"
    )}
/>

Yeah, I might have to re-evaluate how we're handling the dynamic classes by using something like inline styles. Dynamically setting I guess breaks tailwind rules. https://tailwindcss.com/docs/content-configuration#dynamic-class-names:~:text=Don%E2%80%99t%20use%20props%20to%20build%20class%20names%20dynamically

jmderby avatar Sep 27 '24 15:09 jmderby

yeah, classes like border-[${appearance.colors.border}] are known to not work/be flaky

better to use style object for those

mPaella avatar Sep 27 '24 15:09 mPaella

yeah, classes like border-[${appearance.colors.border}] are known to not work/be flaky

better to use style object for those

Yeah, I'm looking at safelisting (https://tailwindcss.com/docs/content-configuration#safelisting-classes) but it seems like inline might be the most reliable method.

jmderby avatar Sep 27 '24 15:09 jmderby

@maxwellfortney @AlbertoElias do you guys want me to prioritize a PR that replaces dynam classes with inline asap?

jmderby avatar Sep 27 '24 15:09 jmderby

not sure safelisting will even work, but i would just go for styles for simplicity + certainty it will work

want me to prioritize a PR

assuming its currently broken, i think that makes sense

in the context of this pr tho, i think we can say the conditional styles not working is not due to the tree shaking

mPaella avatar Sep 27 '24 15:09 mPaella

in the context of this pr tho, i think we can say the conditional styles not working is not due to the tree shaking

Not due to the tree shaking, but something changes in the build process that breaks this while it does work in main. I'll finish testing other apps and report back

AlbertoElias avatar Sep 27 '24 15:09 AlbertoElias

Looking good. But we should wait to merge this until @jmderby fixes the twind stuff on react-ui or development and testing will be a pain

AlbertoElias avatar Sep 27 '24 16:09 AlbertoElias

@mPaella Implemented #805 so this can now be merged.

AlbertoElias avatar Oct 09 '24 16:10 AlbertoElias