Skip to content
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

update client-only-render-external-dependency example #4822

Merged
merged 1 commit into from
Jul 22, 2018
Merged

update client-only-render-external-dependency example #4822

merged 1 commit into from
Jul 22, 2018

Conversation

Tomekmularczyk
Copy link
Contributor

Changes:

  • use dynamic imports instead of require
  • update recharts dependency

import dynamic from 'next/dynamic'

export default dynamic({
modules: props => ({
Copy link
Member

@timneutkens timneutkens Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove props this is going to be removed in Next 7

Copy link
Contributor Author

@Tomekmularczyk Tomekmularczyk Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. Btw I was not sure how to best approach this example.
I tried to just make dynamic imports directly in pages like:

const BarChart = dynamic(import('recharts').then(({ BarChart }) => BarChart), { ssr: false }),
const Bar = dynamic(import('recharts').then(({ Bar }) => Bar), { ssr: false })

But I experienced charts not being drawn. I think that these two components had to be together ready before they were rendered. The above way solved the issue.

I also thought about just making a directory BarChart and LineChart with index.js file exporting:

export default dynamic(import('./BarChart'), { ssr: false });
// ... and
export default dynamic(import('./LineChart'), { ssr: false });

but this would resolve in recharts being bundled twice for these two chunks (and it's quite big).

import dynamic from 'next/dynamic'

export default dynamic({
modules: props => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as my other comment

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine like this 👍

@timneutkens timneutkens merged commit b122296 into vercel:canary Jul 22, 2018
@pengshaosu
Copy link

pengshaosu commented Nov 26, 2018

const JSEncrypt = dynamic(import('jsencrypt').then(({JSEncrypt}) => JSEncrypt}, { ssr: false })

How can use dynamic import correctly?
I follow above but error?
Thx

@lock lock bot locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants