-
Notifications
You must be signed in to change notification settings - Fork 47.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change SSR Fixture to use Partial Hydration
This requires the enableSuspenseServerRenderer flag to be manually enabled for the build to work.
- Loading branch information
1 parent
6ae914c
commit c818d14
Showing
6 changed files
with
100 additions
and
18 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 |
---|---|---|
@@ -1,17 +1,44 @@ | ||
import React, {Component} from 'react'; | ||
import React, {useState, Suspense} from 'react'; | ||
|
||
import Chrome from './Chrome'; | ||
import Page from './Page'; | ||
|
||
export default class App extends Component { | ||
render() { | ||
return ( | ||
<Chrome title="Hello World" assets={this.props.assets}> | ||
function LoadingIndicator({theme}) { | ||
return <div className={theme + '-loading'}>Loading...</div>; | ||
} | ||
|
||
function ThemeToggleButton({theme, onChange}) { | ||
let [targetTheme, setTargetTheme] = useState(theme); | ||
function toggleTheme() { | ||
let newTheme = theme === 'light' ? 'dark' : 'light'; | ||
// High pri, responsive update. | ||
setTargetTheme(newTheme); | ||
// Perform the actual theme change in a separate update. | ||
setTimeout(() => onChange(newTheme), 0); | ||
} | ||
if (targetTheme !== theme) { | ||
return 'Switching to ' + targetTheme + '...'; | ||
} | ||
return ( | ||
<button onClick={toggleTheme}> | ||
Switch to {theme === 'light' ? 'Dark' : 'Light'} theme | ||
</button> | ||
); | ||
} | ||
|
||
export default function App({assets}) { | ||
let [theme, setTheme] = useState('light'); | ||
return ( | ||
<Chrome title="Hello World" assets={assets} theme={theme}> | ||
<div> | ||
<h1>Hello World</h1> | ||
<div> | ||
<h1>Hello World</h1> | ||
<Page /> | ||
<ThemeToggleButton theme={theme} onChange={setTheme} /> | ||
</div> | ||
</Chrome> | ||
); | ||
} | ||
<Suspense fallback={<LoadingIndicator theme={theme} />}> | ||
<Page theme={theme} /> | ||
</Suspense> | ||
</div> | ||
</Chrome> | ||
); | ||
} |
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,3 +1,11 @@ | ||
.bold { | ||
font-weight: bold; | ||
} | ||
.light-box { | ||
background-color: #CCCCCC; | ||
color: #333333; | ||
} | ||
.dark-box { | ||
background-color: #333333; | ||
color: #CCCCCC; | ||
} |
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,6 +1,7 @@ | ||
import React from 'react'; | ||
import {hydrate} from 'react-dom'; | ||
import {unstable_createRoot} from 'react-dom'; | ||
|
||
import App from './components/App'; | ||
|
||
hydrate(<App assets={window.assetManifest} />, document); | ||
let root = unstable_createRoot(document, {hydrate: true}); | ||
root.render(<App assets={window.assetManifest} />); |