Next.js Discord

Discord Forum

Preventing automatic lazy loading components?

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
I have a component that wraps its children to inject a classname using cloneElement, but randomly (or maybe I'm missing something), some of them are being converted to lazy/dynamic load, then the clone fails to transfer the classname...

How can I control it? Is there any way to prevent it? Is there any workaround in NextJS to make cloneElement work also in lazy/dynamic components?

🙏 It's a kind of core feature in my lib.

9 Replies

Transvaal lionOP
Boerboel
I was talking about code. If i may be able to view the code.
Transvaal lionOP
It's pretty hard to share an isolated case because it seems to be something random: if I change anything in the page, the lazy components change.
This is my page code. 😅
It's weird because if I change the components' order on the same page and some hierarchy, the result changes.
Transvaal lionOP
In this example, only the last 5 DebugTextEdit are being converted to lazy-loaded. The other 3 are still being rendered normally.
If I switch their parents' order on the page, all of them are rendered normally.