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

Remove unnecessary async function when preloading async components #42957

Merged
merged 4 commits into from Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 6 additions & 17 deletions packages/next/server/app-render.tsx
Expand Up @@ -59,23 +59,12 @@ function preloadComponent(Component: any, props: any) {
}
try {
let result = Component(props)
if (result && result.then) {
result = result
.then((res: any) => {
return { success: res }
})
.catch((err: Error) => {
return { error: err }
})
return async () => {
const res = await result
if (res.error) {
throw res.error
}
if (res.success) {
return res.success
}
}
if (result && typeof result.then === 'function') {
// Catch promise rejections to prevent unhandledRejection errors
result.then(
() => {},
() => {}
)
}
return function () {
// We know what this component will render already.
Expand Down