-
Notifications
You must be signed in to change notification settings - Fork 27k
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
v13.0.2 broke something to do with dynamic imports #43483
Comments
Firstly Please create a reproduction example, as it helps people who want to help try and test and maybe come up with a solution faster. You could easily create one with stackblitz, here is a simple link to setup for reproduction : https://stackblitz.com/fork/github/vercel/next.js/tree/canary/examples/reproduction-template Secondly, I’ve had some problems with dynamic imports and I think it is because they can’t be used in server components, to import them you could try putting the |
There is also a problem with the code you gave, next/dynamic takes a callback but you wrote an import directly, it should be : const QuillNoSSRWrapper = dynamic(() => import("react-quill"), {
ssr: false,
loading: () => <p>Loading ...</p>,
}); |
Ah thank you @Fredkiss3, that seems to be it. |
I tried that but it doesn't work. Looks like this dynamic import is always pre-rendered despite {ssr: false}. |
@njarraud I think that’s intended, server components are only executed once on the server, they can’t support dynamic import since dynamic import needs to happen on the client (most of the time). |
I used the dynamic import of a 'use client' component inside another 'use client' component. |
I dont understand you well, could you give an example of what you are trying to do ? |
I want to execute some code on the client only (as it uses 'use client';
const ChildComponent = dynamic(() => import('./ChildComponent'), { ssr: false });
const ParentComponent = () => {
return <ChildComponent />
} 'use client';
// Import libraries using browser only API to use in ChildComponent
const ChildComponent = () => {
console.log('Shall not be logged in the server console but it is')
return <div>{whatever here}</div>
} |
You're totally right, there is a bug with dynamic components, when is tested your within The wrokaround i found is to not show the dynamic component on the first render, so that it won't run on the server, then run a useEffect on the client to show after, like this : 'use client';
import { useEffect, useState } from 'react';
import dynamic from 'next/dynamic';
const ChildComponent = dynamic(() => import('./ChildComponent'), {
ssr: false,
});
export default function ParentComponent() {
const [isChildShown, setShowChild] = useState(false);
useEffect(() => {
setShowChild(true);
}, []);
return <>{isChildShown && <ChildComponent />}</>;
} I also managed to do a little reproduction template here : https://stackblitz.com/edit/nextjs-zkhpkm?file=app%2Fpage.js,pages%2Fproblem.js |
Openned an issue here : #43764 |
@njarraud This issue has been fixed in the latest canary release (you can install it with |
Thanks, it works. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
v13.0.2 broke dynamic imports. I'm importing the quill editor (https://github.com/zenoamaro/react-quill) and it's throwing a "document is not defined" error. I've verified it works on previous versions before v13.0.2, but no versions starting at v13.0.2.
Note: this only happens after a build (
next build && next start
), it is not occurring withnext dev
Here is what my quill component looks like:
and here is the error:
Expected Behavior
It should render without an error in v13.0.2+.
Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
N/A
To Reproduce
Take my quill component example above and render the component in your code, run
next build && next start
and try to view the page it is rendering on.It will work on v13.0.1 and not on v13.0.2.
The text was updated successfully, but these errors were encountered: