Unexpected Behavior with loading.tsx
and Lazy-Loaded Components Using dynamic()
#74045
Unanswered
programming-with-ia
asked this question in
App Router
Replies: 1 comment
-
currently i am handling that issue like this. function Wrapper({ children }: React.ComponentPropsWithRef<"div">) {
useEffect(() => {
const element = document.getElementById("lazy-load-fix");
if (!element) return;
console.log("observing...", element);
const observer = new MutationObserver(() => {
element.style.display = "unset";
});
observer.observe(element, {
attributes: true,
attributeFilter: ["style"],
});
return () => observer.disconnect();
}, []);
return (
<div id="lazy-load-fix" className="!contents">
{children}
</div>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Unexpected Behavior with
loading.tsx
and Lazy-Loaded Components Usingdynamic()
When utilizing a
loading.tsx
file at the root of a route alongside lazy-loaded components viadynamic()
(fromnext/dynamic
), I observed an unexpected behavior:All child elements passed from the
page.tsx
file are temporarily assigneddisplay: none !important;
until the lazy-loaded component is fully loaded. This causes them to be hidden during the loading phase, which may not be the intended outcome.Environment:
Beta Was this translation helpful? Give feedback.
All reactions