Skip to content

Commit

Permalink
RSC: Use the default entry.client file (#9654)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Dec 8, 2023
1 parent fb3f1fb commit 3f6e7c1
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 66 deletions.
12 changes: 12 additions & 0 deletions __fixtures__/test-project-rsa/web/src/App.tsx
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 __fixtures__/test-project-rsa/web/src/entry.client.tsx
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 __fixtures__/test-project-rsc-external-packages/web/src/App.tsx
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
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 />)
}
25 changes: 7 additions & 18 deletions packages/cli/src/commands/experimental/setupRscHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ export const handler = async ({ force, verbose }) => {
})
},
},
{
title: 'Removing App.tsx...',
task: async () => {
const appPath =
rwPaths.web.app ?? path.join(rwPaths.web.src, 'App.tsx')

fs.rmSync(appPath, { force: true })
},
},
{
title: 'Adding Pages...',
task: async () => {
Expand Down Expand Up @@ -284,19 +275,17 @@ export const handler = async ({ force, verbose }) => {
},
},
{
title: 'Overwrite entry.client.tsx...',
title: 'Overwrite App.tsx...',
task: async () => {
const entryClientTemplate = fs.readFileSync(
path.resolve(
__dirname,
'templates',
'rsc',
'entry.client.tsx.template'
),
const appTemplate = fs.readFileSync(
path.resolve(__dirname, 'templates', 'rsc', 'App.tsx.template'),
'utf-8'
)

writeFile(rwPaths.web.entryClient, entryClientTemplate, {
const appPath =
rwPaths.web.app ?? path.join(rwPaths.web.src, 'App.tsx')

writeFile(appPath, appTemplate, {
overwriteExisting: true,
})
},
Expand Down
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 was deleted.

0 comments on commit 3f6e7c1

Please sign in to comment.