-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent errors in React components from crashing the dev server (#4816)
* Prevent errors in React components from crashing the dev server * Add a changeset * Fix test when running in the build
- Loading branch information
Showing
6 changed files
with
48 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,5 @@ | ||
--- | ||
'@astrojs/react': patch | ||
--- | ||
|
||
Prevent errors in React components from crashing the dev server |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/react-component/src/components/ImportsThrowsAnError.jsx
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 ThrowsAnError from "./ThrowsAnError"; | ||
|
||
export default function() { | ||
return <> | ||
<ThrowsAnError /> | ||
</> | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/react-component/src/components/ThrowsAnError.jsx
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,15 @@ | ||
import { useState } from 'react'; | ||
|
||
export default function() { | ||
let player = undefined; | ||
// This is tested in dev mode, so make it work during the build to prevent | ||
// breaking other tests. | ||
if(import.meta.env.MODE === 'production') { | ||
player = {}; | ||
} | ||
const [] = useState(player.currentTime || null); | ||
|
||
return ( | ||
<div>Should have thrown</div> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/react-component/src/pages/error-rendering.astro
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,11 @@ | ||
--- | ||
import ImportsThrowsAnError from '../components/ImportsThrowsAnError'; | ||
--- | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<ImportsThrowsAnError /> | ||
</body> | ||
</html> |
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