-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error checks and tests to next-dynamic
- Loading branch information
Hannes Lund
committed
Nov 22, 2021
1 parent
c2e73ea
commit 63bd6a5
Showing
16 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Invalid argument in `next/dynamic` call | ||
|
||
#### Why This Error Occurred | ||
|
||
You have passed an invalid argument to a `next/dynamic` call. | ||
|
||
- The `import()` call must be inside the `dynamic()` call. | ||
- The options object literal must be created inside the `dynamic()` call. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
**Before** | ||
|
||
```jsx | ||
import dynamic from 'next/dynamic' | ||
|
||
const module = () => import('../components/hello') | ||
const options = { loading: () => <p>...</p>, ssr: false } | ||
const DynamicComponent = dynamic(module, options) | ||
``` | ||
|
||
**After** | ||
|
||
```jsx | ||
import dynamic from 'next/dynamic' | ||
|
||
const DynamicComponent = dynamic(() => import('../components/hello'), { | ||
loading: () => <p>...</p>, | ||
ssr: false, | ||
}) | ||
``` | ||
|
||
### Useful Links | ||
|
||
- [Dynamic Import](https://nextjs.org/docs/advanced-features/dynamic-import) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/next-swc/crates/core/tests/errors/next-dynamic/import-as-variable/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const module = () => import('../components/hello') | ||
const DynamicComponentWithCustomLoading = dynamic(module) |
4 changes: 4 additions & 0 deletions
4
packages/next-swc/crates/core/tests/errors/next-dynamic/import-as-variable/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const module = () => import('../components/hello') | ||
const DynamicComponentWithCustomLoading = dynamic(module) |
7 changes: 7 additions & 0 deletions
7
packages/next-swc/crates/core/tests/errors/next-dynamic/import-as-variable/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: import() has to be inside the dynamic() call. | ||
Read more: https://nextjs.org/docs/messages/invalid-dynamic-arguments | ||
--> input.js:4:43 | ||
| | ||
4 | const DynamicComponentWithCustomLoading = dynamic(module) | ||
| ^^^^^^^ | ||
|
3 changes: 3 additions & 0 deletions
3
packages/next-swc/crates/core/tests/errors/next-dynamic/no-arguments/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const DynamicComponent = dynamic() |
3 changes: 3 additions & 0 deletions
3
packages/next-swc/crates/core/tests/errors/next-dynamic/no-arguments/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const DynamicComponent = dynamic() |
6 changes: 6 additions & 0 deletions
6
packages/next-swc/crates/core/tests/errors/next-dynamic/no-arguments/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error: next/dynamic requires at least one argument | ||
--> input.js:3:26 | ||
| | ||
3 | const DynamicComponent = dynamic() | ||
| ^^^^^^^ | ||
|
7 changes: 7 additions & 0 deletions
7
packages/next-swc/crates/core/tests/errors/next-dynamic/options-as-variable/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const options = { loading: () => <p>...</p>, ssr: false } | ||
const DynamicComponentWithCustomLoading = dynamic( | ||
() => import('../components/hello'), | ||
options | ||
) |
7 changes: 7 additions & 0 deletions
7
packages/next-swc/crates/core/tests/errors/next-dynamic/options-as-variable/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dynamic from 'next/dynamic'; | ||
|
||
const options = { loading: () => <p>...</p>, ssr: false }; | ||
const DynamicComponentWithCustomLoading = dynamic( | ||
() => import('../components/hello'), | ||
options | ||
); |
7 changes: 7 additions & 0 deletions
7
packages/next-swc/crates/core/tests/errors/next-dynamic/options-as-variable/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: Second argument must be an object literal. | ||
Read more: https://nextjs.org/docs/messages/invalid-dynamic-arguments | ||
--> input.js:4:43 | ||
| | ||
4 | const DynamicComponentWithCustomLoading = dynamic( | ||
| ^^^^^^^ | ||
|
7 changes: 7 additions & 0 deletions
7
packages/next-swc/crates/core/tests/errors/next-dynamic/too-many-arguments/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const DynamicComponentWithCustomLoading = dynamic( | ||
() => import('../components/hello'), | ||
{ loading: () => <p>...</p> }, | ||
"3rd" | ||
) |
7 changes: 7 additions & 0 deletions
7
packages/next-swc/crates/core/tests/errors/next-dynamic/too-many-arguments/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const DynamicComponentWithCustomLoading = dynamic( | ||
() => import('../components/hello'), | ||
{ loading: () => <p>...</p> }, | ||
"3rd" | ||
) |
6 changes: 6 additions & 0 deletions
6
packages/next-swc/crates/core/tests/errors/next-dynamic/too-many-arguments/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
error: next/dynamic only accepts 2 arguments | ||
--> input.js:3:43 | ||
| | ||
3 | const DynamicComponentWithCustomLoading = dynamic( | ||
| ^^^^^^^ | ||
|