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

nextjs app-dir bug with dynamic imports #43764

Closed
1 task done
Fredkiss3 opened this issue Dec 6, 2022 · 3 comments · Fixed by #43901
Closed
1 task done

nextjs app-dir bug with dynamic imports #43764

Fredkiss3 opened this issue Dec 6, 2022 · 3 comments · Fixed by #43901
Assignees
Labels
bug Issue was opened via the bug report template. Lazy Loading Related to Next.js Lazy Loading (e.g., `next/dynamic` or `React.lazy`).

Comments

@Fredkiss3
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: Ubuntu 20.04.0 LTS Tue Dec 06 2022 14:12:26 GMT+0100 (heure normale d’Europe centrale)
Binaries:
  Node: 16.14.2
  npm: 7.17.0
  Yarn: 1.22.19
  pnpm: 7.13.6
Relevant packages:
  next: 13.0.6
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Dynamic imports (next/dynamic)

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://stackblitz.com/edit/nextjs-zkhpkm?file=app%2Ftest%2Fpage.js

To Reproduce

Go to the page /test on your browser, you'll see that the console.log which is supposed to only run on client get to run also on the server. You will also see that nextjs show that hydration errors occurs.

It seems like the component which is marked with ssr: false still get to run on the server and you can even inspect the source code generated and you will see the content of the server .
You can check the page at /problem which is located in the pages directory and it seems to work there without an issue.

Describe the Bug

Within app directory nextjs seems to ignore the parameter ssr: false when using dynamic imports and always run the component on the server. On top of that it produces a hydration error when used.

This seems to only occur within the app directory and not the pages directory.
For information i used the import on pages with the 'use client' directive on top.

Expected Behavior

Nextjs should respect the parameter ssr: false of dynamic imports and not try to render the page on the server.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@Fredkiss3 Fredkiss3 added the bug Issue was opened via the bug report template. label Dec 6, 2022
@Fredkiss3
Copy link
Contributor Author

This issue has been fixed in the latest canary release (you can install it with next@canary and should be fixed by the time next@13.0.7 come out).

thank you

@Fredkiss3 Fredkiss3 reopened this Dec 8, 2022
@Fredkiss3
Copy link
Contributor Author

There is another issue happening when using dynamic imports with ssr: false, the props aren't passed to the component and are only passed if i use ssr: true (or if i omit the SSR option entirely).

I updated the reproduction code to the latest release : https://stackblitz.com/edit/nextjs-zkhpkm?file=app%2Ftest%2Fpage.js

@huozhi huozhi added the Lazy Loading Related to Next.js Lazy Loading (e.g., `next/dynamic` or `React.lazy`). label Dec 9, 2022
@huozhi huozhi self-assigned this Dec 9, 2022
@kodiakhq kodiakhq bot closed this as completed in #43901 Dec 9, 2022
kodiakhq bot pushed a commit that referenced this issue Dec 9, 2022
## Bug

Fixes: #43764

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Lazy Loading Related to Next.js Lazy Loading (e.g., `next/dynamic` or `React.lazy`).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants