-
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: Fake server-side routing (#9593)
- Loading branch information
Showing
36 changed files
with
373 additions
and
72 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,2 @@ | ||
.about-page { | ||
} |
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,26 @@ | ||
import { Assets } from '@redwoodjs/vite/assets' | ||
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' | ||
|
||
import { Counter } from './Counter' | ||
|
||
import './AboutPage.css' | ||
|
||
// TODO (RSC) Something like this will probably be needed | ||
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; | ||
|
||
globalThis.rwRscGlobal = new ProdRwRscServerGlobal() | ||
|
||
const AboutPage = () => { | ||
return ( | ||
<div className="about-page"> | ||
{/* TODO (RSC) <Assets /> should be part of the router later */} | ||
<Assets /> | ||
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}> | ||
<h1>About Redwood</h1> | ||
<Counter /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default AboutPage |
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
.home-page { | ||
} |
File renamed without changes.
14 changes: 7 additions & 7 deletions
14
...xtures__/test-project-rsa/web/src/App.tsx → ...s__/test-project-rsa/web/src/HomePage.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,29 +1,29 @@ | ||
import { Assets } from '@redwoodjs/vite/assets' | ||
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' | ||
|
||
// @ts-expect-error no types | ||
import styles from './App.module.css' | ||
import { onSend } from './chat' | ||
import { Form } from './Form' | ||
// @ts-expect-error no types | ||
import styles from './HomePage.module.css' | ||
|
||
import './App.css' | ||
import './HomePage.css' | ||
|
||
// TODO (RSC) Something like this will probably be needed | ||
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; | ||
|
||
globalThis.rwRscGlobal = new ProdRwRscServerGlobal() | ||
|
||
const App = ({ name = 'Anonymous' }) => { | ||
const HomePage = ({ name = 'Anonymous' }) => { | ||
return ( | ||
<> | ||
<div className="home-page"> | ||
{/* TODO (RSC) <Assets /> should be part of the router later */} | ||
<Assets /> | ||
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}> | ||
<h1 className={styles.title}>Hello {name}!!</h1> | ||
<Form onSend={onSend} /> | ||
</div> | ||
</> | ||
</div> | ||
) | ||
} | ||
|
||
export default App | ||
export default HomePage |
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 |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import { createRoot } from 'react-dom/client' | ||
|
||
import { Route, Router, Set } from '@redwoodjs/router' | ||
import { serve } from '@redwoodjs/vite/client' | ||
|
||
import NavigationLayout from './layouts/NavigationLayout/NavigationLayout' | ||
import NotFoundPage from './pages/NotFoundPage/NotFoundPage' | ||
|
||
const redwoodAppElement = document.getElementById('redwood-app') | ||
|
||
const App = serve('App') | ||
const AboutPage = serve('AboutPage') | ||
const HomePage = serve('HomePage') | ||
|
||
const root = createRoot(redwoodAppElement) | ||
root.render(<App name="Redwood RSAs" />) | ||
|
||
const App = () => { | ||
return ( | ||
<Router> | ||
<Set wrap={NavigationLayout}> | ||
<Route path="/" page={HomePage} name="home" /> | ||
<Route path="/about" page={AboutPage} name="about" /> | ||
</Set> | ||
<Route notfound page={NotFoundPage} /> | ||
</Router> | ||
) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
import { LocationProvider } from '@redwoodjs/router' | ||
|
||
import App from './App' | ||
import { Document } from './Document' | ||
import HomePage from './HomePage' | ||
|
||
interface Props { | ||
url: string | ||
css: string[] | ||
meta?: any[] | ||
} | ||
|
||
export const ServerEntry: React.FC<Props> = ({ url, css, meta }) => { | ||
export const ServerEntry: React.FC<Props> = ({ css, meta }) => { | ||
return ( | ||
<LocationProvider location={{ pathname: url }}> | ||
<Document css={css} meta={meta}> | ||
<App /> | ||
</Document> | ||
</LocationProvider> | ||
<Document css={css} meta={meta}> | ||
<HomePage /> | ||
</Document> | ||
) | ||
} |
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,4 @@ | ||
html, body { | ||
margin: 0; | ||
padding: 0; | ||
} |
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
32 changes: 32 additions & 0 deletions
32
__fixtures__/test-project-rsa/web/src/layouts/NavigationLayout/NavigationLayout.css
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,32 @@ | ||
.navigation-layout { | ||
& nav { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 10px; | ||
background-color: color-mix(in srgb, yellow 50%, transparent); | ||
border-bottom: 2px dashed color-mix(in srgb, yellow 90%, black); | ||
} | ||
|
||
& ul { | ||
list-style: none; | ||
display: flex; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
& li { | ||
margin-right: 10px; | ||
} | ||
|
||
& a { | ||
text-decoration: none; | ||
color: #333; | ||
padding: 5px; | ||
border-bottom: 2px solid transparent; | ||
} | ||
|
||
& a:hover { | ||
border-bottom: 2px solid #333; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
__fixtures__/test-project-rsa/web/src/layouts/NavigationLayout/NavigationLayout.stories.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,13 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import NavigationLayout from './NavigationLayout' | ||
|
||
const meta: Meta<typeof NavigationLayout> = { | ||
component: NavigationLayout, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof NavigationLayout> | ||
|
||
export const Primary: Story = {} |
14 changes: 14 additions & 0 deletions
14
__fixtures__/test-project-rsa/web/src/layouts/NavigationLayout/NavigationLayout.test.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,14 @@ | ||
import { render } from '@redwoodjs/testing/web' | ||
|
||
import NavigationLayout from './NavigationLayout' | ||
|
||
// Improve this test with help from the Redwood Testing Doc: | ||
// https://redwoodjs.com/docs/testing#testing-pages-layouts | ||
|
||
describe('NavigationLayout', () => { | ||
it('renders successfully', () => { | ||
expect(() => { | ||
render(<NavigationLayout />) | ||
}).not.toThrow() | ||
}) | ||
}) |
27 changes: 27 additions & 0 deletions
27
__fixtures__/test-project-rsa/web/src/layouts/NavigationLayout/NavigationLayout.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,27 @@ | ||
import { Link, routes } from '@redwoodjs/router' | ||
|
||
import './NavigationLayout.css' | ||
|
||
type NavigationLayoutProps = { | ||
children?: React.ReactNode | ||
} | ||
|
||
const NavigationLayout = ({ children }: NavigationLayoutProps) => { | ||
return ( | ||
<div className="navigation-layout"> | ||
<nav> | ||
<ul> | ||
<li> | ||
<Link to={routes.home()}>Home</Link> | ||
</li> | ||
<li> | ||
<Link to={routes.about()}>About</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
<main>{children}</main> | ||
</div> | ||
) | ||
} | ||
|
||
export default NavigationLayout |
2 changes: 2 additions & 0 deletions
2
__fixtures__/test-project-rsc-external-packages/web/src/AboutPage.css
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,2 @@ | ||
.about-page { | ||
} |
26 changes: 26 additions & 0 deletions
26
__fixtures__/test-project-rsc-external-packages/web/src/AboutPage.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,26 @@ | ||
import { Assets } from '@redwoodjs/vite/assets' | ||
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal' | ||
|
||
import { Counter } from './Counter' | ||
|
||
import './AboutPage.css' | ||
|
||
// TODO (RSC) Something like this will probably be needed | ||
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal; | ||
|
||
globalThis.rwRscGlobal = new ProdRwRscServerGlobal() | ||
|
||
const AboutPage = () => { | ||
return ( | ||
<div className="about-page"> | ||
{/* TODO (RSC) <Assets /> should be part of the router later */} | ||
<Assets /> | ||
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}> | ||
<h1>About Redwood</h1> | ||
<Counter /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default AboutPage |
3 changes: 0 additions & 3 deletions
3
__fixtures__/test-project-rsc-external-packages/web/src/App.css
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
__fixtures__/test-project-rsc-external-packages/web/src/HomePage.css
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,2 @@ | ||
.home-page { | ||
} |
File renamed without changes.
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
22 changes: 20 additions & 2 deletions
22
__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,10 +1,28 @@ | ||
import { createRoot } from 'react-dom/client' | ||
|
||
import { Route, Router, Set } from '@redwoodjs/router' | ||
import { serve } from '@redwoodjs/vite/client' | ||
|
||
import NavigationLayout from './layouts/NavigationLayout/NavigationLayout' | ||
import NotFoundPage from './pages/NotFoundPage/NotFoundPage' | ||
|
||
const redwoodAppElement = document.getElementById('redwood-app') | ||
|
||
const App = serve('App') | ||
const AboutPage = serve('AboutPage') | ||
const HomePage = serve('HomePage') | ||
|
||
const root = createRoot(redwoodAppElement) | ||
root.render(<App name="Redwood RSAs" />) | ||
|
||
const App = () => { | ||
return ( | ||
<Router> | ||
<Set wrap={NavigationLayout}> | ||
<Route path="/" page={HomePage} name="home" /> | ||
<Route path="/about" page={AboutPage} name="about" /> | ||
</Set> | ||
<Route notfound page={NotFoundPage} /> | ||
</Router> | ||
) | ||
} | ||
|
||
root.render(<App />) |
Oops, something went wrong.