-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSC: Use the default entry.client file (#9654)
- Loading branch information
Showing
7 changed files
with
77 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { FatalErrorBoundary } from '@redwoodjs/web' | ||
|
||
import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' | ||
import Routes from './Routes' | ||
|
||
const App = () => ( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<Routes /> | ||
</FatalErrorBoundary> | ||
) | ||
|
||
export default App |
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 |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import { createRoot } from 'react-dom/client' | ||
|
||
import { FatalErrorBoundary } from '@redwoodjs/web' | ||
|
||
import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' | ||
import Routes from './Routes' | ||
import { hydrateRoot, createRoot } from 'react-dom/client' | ||
|
||
import App from './App' | ||
/** | ||
* When `#redwood-app` isn't empty then it's very likely that you're using | ||
* prerendering. So React attaches event listeners to the existing markup | ||
* rather than replacing it. | ||
* https://reactjs.org/docs/react-dom-client.html#hydrateroot | ||
*/ | ||
const redwoodAppElement = document.getElementById('redwood-app') | ||
|
||
const root = createRoot(redwoodAppElement) | ||
|
||
const App = () => { | ||
return ( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<Routes /> | ||
</FatalErrorBoundary> | ||
if (!redwoodAppElement) { | ||
throw new Error( | ||
"Could not find an element with ID 'redwood-app'. Please ensure it exists in your 'web/src/index.html' file." | ||
) | ||
} | ||
|
||
root.render(<App />) | ||
if (redwoodAppElement.children?.length > 0) { | ||
hydrateRoot(redwoodAppElement, <App />) | ||
} else { | ||
const root = createRoot(redwoodAppElement) | ||
root.render(<App />) | ||
} |
12 changes: 12 additions & 0 deletions
12
__fixtures__/test-project-rsc-external-packages/web/src/App.tsx
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,12 @@ | ||
import { FatalErrorBoundary } from '@redwoodjs/web' | ||
|
||
import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' | ||
import Routes from './Routes' | ||
|
||
const App = () => ( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<Routes /> | ||
</FatalErrorBoundary> | ||
) | ||
|
||
export default App |
31 changes: 17 additions & 14 deletions
31
__fixtures__/test-project-rsc-external-packages/web/src/entry.client.tsx
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 |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import { createRoot } from 'react-dom/client' | ||
|
||
import { FatalErrorBoundary } from '@redwoodjs/web' | ||
|
||
import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' | ||
import Routes from './Routes' | ||
import { hydrateRoot, createRoot } from 'react-dom/client' | ||
|
||
import App from './App' | ||
/** | ||
* When `#redwood-app` isn't empty then it's very likely that you're using | ||
* prerendering. So React attaches event listeners to the existing markup | ||
* rather than replacing it. | ||
* https://reactjs.org/docs/react-dom-client.html#hydrateroot | ||
*/ | ||
const redwoodAppElement = document.getElementById('redwood-app') | ||
|
||
const root = createRoot(redwoodAppElement) | ||
|
||
const App = () => { | ||
return ( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<Routes /> | ||
</FatalErrorBoundary> | ||
if (!redwoodAppElement) { | ||
throw new Error( | ||
"Could not find an element with ID 'redwood-app'. Please ensure it exists in your 'web/src/index.html' file." | ||
) | ||
} | ||
|
||
root.render(<App />) | ||
if (redwoodAppElement.children?.length > 0) { | ||
hydrateRoot(redwoodAppElement, <App />) | ||
} else { | ||
const root = createRoot(redwoodAppElement) | ||
root.render(<App />) | ||
} |
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
12 changes: 12 additions & 0 deletions
12
packages/cli/src/commands/experimental/templates/rsc/App.tsx.template
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,12 @@ | ||
import { FatalErrorBoundary } from '@redwoodjs/web' | ||
|
||
import FatalErrorPage from './pages/FatalErrorPage/FatalErrorPage' | ||
import Routes from './Routes' | ||
|
||
const App = () => ( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<Routes /> | ||
</FatalErrorBoundary> | ||
) | ||
|
||
export default App |
20 changes: 0 additions & 20 deletions
20
packages/cli/src/commands/experimental/templates/rsc/entry.client.tsx.template
This file was deleted.
Oops, something went wrong.