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

When second parameter of next/dynamic is a variable, the loading component doesn't appear #31520

Closed
jasonbarry opened this issue Nov 16, 2021 · 2 comments · Fixed by #31683
Closed
Labels
Lazy Loading Related to Next.js Lazy Loading (e.g., `next/dynamic` or `React.lazy`). SWC Related to minification/transpilation in Next.js.

Comments

@jasonbarry
Copy link

What version of Next.js are you using?

12.0.4-canary.15

What version of Node.js are you using?

v17.0.1

What browser are you using?

Safari 15.1

What operating system are you using?

macOS 12.0.1

How are you deploying your application?

Netlify (bug appears locally too)

Describe the Bug

In Next.js 11, I had code like

const options = {
  loading: () => <Loading />,
  ssr: false,
}
const LazyThing = dynamic(() => import('~/components/LazyThing'), options)

which would display <Loading /> while the LazyThing chunk was fetched.

In Next.js 12, the above code sample doesn't display <Loading /> while the chunk gets fetched. Instead, the code needs to be changed to

const LazyThing = dynamic(() => import('~/components/LazyThing'), {
  loading: () => <Loading />,
  ssr: false,
})

for the <Loading /> component to be displayed as expected.

Expected Behavior

I would expect that the behavior wouldn't be different whether or not the second parameter of next/dynamic is a variable.

To Reproduce

With latest Next.js 12, try passing a variable as the second parameter of next/dynamic vs passing the object literal directly. You should notice that when the options are passed as a variable, the component specified by the loading key never appears.

@jasonbarry jasonbarry added the bug Issue was opened via the bug report template. label Nov 16, 2021
@timneutkens timneutkens added Lazy Loading Related to Next.js Lazy Loading (e.g., `next/dynamic` or `React.lazy`). SWC Related to minification/transpilation in Next.js. labels Nov 19, 2021
@timneutkens
Copy link
Member

That usage should probably throw an error in the compiler tbh, with Next.js 11 it would break too but in a non-obvious way probably like hydration errors and such.

@timneutkens timneutkens added kind: bug and removed bug Issue was opened via the bug report template. labels Nov 19, 2021
@kodiakhq kodiakhq bot closed this as completed in #31683 Nov 26, 2021
kodiakhq bot pushed a commit that referenced this issue Nov 26, 2021
fixes #31520

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
@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 27, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
fixes vercel#31520

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Lazy Loading Related to Next.js Lazy Loading (e.g., `next/dynamic` or `React.lazy`). SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants