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

Next.js pages with dynamic content do not server side render #8174

Closed
Brianvdb opened this issue Jul 30, 2019 · 4 comments
Closed

Next.js pages with dynamic content do not server side render #8174

Brianvdb opened this issue Jul 30, 2019 · 4 comments

Comments

@Brianvdb
Copy link

Bug report

Describe the bug

Dynamic import does not render in HTML.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Start a getting started project
  2. Create a file: pages/[id].jsx
  3. Paste following code:
import {useRouter} from 'next/router';
import dynamic from 'next/dynamic'
import '../styles/index.css';
import React from 'react';

export default function Page() {
    const router = useRouter();
    const id = router.query.id;

    const Comp = dynamic(() => import(`../src/components/footer`), {ssr: true});

    return (
        <>
            <Comp id={id}/>
        </>
    );
}
  1. Page renders fine with the dynamic import. But its not in the HTML visible.

Expected behavior

HTML of the custom component should be visible

System information

  • OS: macOS & WIndows
  • Browser (if applies) [all]
  • Version of Next.js: [9.0.2]

Additional context

It does work if i declare Comp above the function. But the component loaded will be based on the id of the query. For simplicity its now hardcoded for footer.

@timneutkens
Copy link
Member

dynamic() should be used at the top level of a module as it registers itself for hydration. If you want to dynamically load multiple files you can add multiple imports and render based on an object.

@Brianvdb
Copy link
Author

@timneutkens thanks I implemented that now, but this raises the following issue: #8186

@dani97
Copy link

dani97 commented Apr 13, 2020

To fix this warning, I have to make ssr: false for the component

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants