-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implenented portals - Fixed refs - Fixed unmountComponentAtNode - Fix issue with work loop when loop resets in sync mode (due to suspense/error boundary) and the boundary is before top fiber. -
- Loading branch information
Showing
16 changed files
with
242 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import Brahmos from '../src'; | ||
|
||
class ErrorBoundary extends Brahmos.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { error: null, errorInfo: null }; | ||
} | ||
|
||
static getDerivedStateFromError(error) { | ||
return { error }; | ||
} | ||
|
||
componentDidCatch(error, errorInfo) { | ||
// Catch errors in any components below and re-render with error message | ||
this.setState({ | ||
error: error, | ||
errorInfo: errorInfo, | ||
}); | ||
// You can also log error messages to an error reporting service here | ||
} | ||
|
||
render() { | ||
if (this.state.error) { | ||
// Error path | ||
return ( | ||
<div> | ||
<h2>Something went wrong.</h2> | ||
<details style={{ whiteSpace: 'pre-wrap' }}> | ||
{this.state.error && this.state.error.toString()} | ||
<br /> | ||
{this.state.errorInfo && this.state.errorInfo.componentStack} | ||
</details> | ||
</div> | ||
); | ||
} | ||
// Normally, just render children | ||
return this.props.children; | ||
} | ||
} | ||
|
||
class BuggyCounter extends Brahmos.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { counter: 0 }; | ||
this.handleClick = this.handleClick.bind(this); | ||
} | ||
|
||
handleClick() { | ||
this.setState(({ counter }) => ({ | ||
counter: counter + 1, | ||
})); | ||
} | ||
|
||
render() { | ||
if (this.state.counter === 5) { | ||
// Simulate a JS error | ||
throw new Error('I crashed!'); | ||
} | ||
return <h1 onClick={this.handleClick}>{this.state.counter}</h1>; | ||
} | ||
} | ||
|
||
export default function ErrorBoundaryExample() { | ||
return ( | ||
<div> | ||
<p> | ||
<b> | ||
This is an example of error boundaries in React 16. | ||
<br /> | ||
<br /> | ||
Click on the numbers to increase the counters. | ||
<br /> | ||
The counter is programmed to throw when it reaches 5. This simulates a JavaScript error in | ||
a component. | ||
</b> | ||
</p> | ||
<hr /> | ||
<ErrorBoundary> | ||
<p> | ||
These two counters are inside the same error boundary. If one crashes, the error boundary | ||
will replace both of them. | ||
</p> | ||
<BuggyCounter /> | ||
<BuggyCounter /> | ||
</ErrorBoundary> | ||
<hr /> | ||
<p> | ||
These two counters are each inside of their own error boundary. So if one crashes, the other | ||
is not affected. | ||
</p> | ||
<ErrorBoundary> | ||
<BuggyCounter /> | ||
</ErrorBoundary> | ||
<ErrorBoundary> | ||
<BuggyCounter /> | ||
</ErrorBoundary> | ||
</div> | ||
); | ||
} |
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
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
Oops, something went wrong.