-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add error boundary to dynamic component
- Loading branch information
Showing
10 changed files
with
102 additions
and
89 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
|
||
export const NEXT_DYNAMIC_NO_SSR_CODE = 'DYNAMIC_SERVER_USAGE' | ||
|
||
class DynamicErrorBoundary extends React.Component< | ||
{ children: React.ReactNode }, | ||
{ noSSR: boolean } | ||
> { | ||
constructor(props: { children: React.ReactNode }) { | ||
super(props) | ||
this.state = { noSSR: false } | ||
} | ||
|
||
static getDerivedStateFromError(error: any) { | ||
console.log('error.digest', error.digest, error.message) | ||
if (error.digest === 'DYNAMIC_SERVER_USAGE') { | ||
return { noSSR: true } | ||
} | ||
// Re-throw if error is not for dynamic | ||
throw error | ||
} | ||
|
||
render() { | ||
if (this.state.noSSR) { | ||
return null | ||
} | ||
return this.props.children | ||
} | ||
} | ||
|
||
export default function DynamicBoundary({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return <DynamicErrorBoundary>{children}</DynamicErrorBoundary> | ||
} |
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: 1 addition & 3 deletions
4
test/e2e/app-dir/app/app/dashboard/index/dynamic-imports/dynamic-server.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