Deferring dynamic import to client on Next 13 build #44940
Unanswered
cereallarceny
asked this question in
Help
Replies: 1 suggested answer 6 replies
{{editor}}'s edit
{{actor}} deleted this content
.
{{editor}}'s edit
Something went wrong.
-
Hide the Icon behind a In Server Components, and React 18, suspense boundaries might be awaited on the server, depending on whether or not we tell |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I've integrated TinaCMS into my Next 13 app, using the experimental app directory. As part of this, my CMS schema allows for the selection of an icon from the popular react-icons library. This allows content authors to be able to customize the icon for any given page section to their liking, without developer intervention. The cost of this decision is that we now have pretty sizeable "First Load JS" (upwards of 700-800kb per page). I temporarily disabled dynamic icons and re-ran the build, and immediately noticed a roughly ~400kb bundle size drop - effectively a 50-60% improvement on some pages.
With that said, I can't realistically disable this functionality, but I'd love to see the loading of icons deferred to the client and off of my "First Load JS". On the other hand, it's somewhat hard for me to tell if that "First Load JS" includes client-side components. Since Next 13 dropped, I've been finding it hard to determine what in my component stack is being rendered as a client component and what's being rendered as a server component. Anyhow, let's dive into the code I've got so far, maybe there's a way to bring these build sizes down:
This allows the implementation to look something like this:
<DynamicIcon icon="FaBeer" {...someOtherProps} />
. My CMS is the one providing me the string"FaBeer"
in this case.I'll be totally honest, the use of😆
dynamic()
,ssr: false
,'use client'
are just me throwing things at the wall. I'm not committed to any of those decisions and will take any help I can get in reducing the bundle size. To cap it off, here's a screenshot of my editor yelling at me for such a massive, shameful import.Beta Was this translation helpful? Give feedback.