-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- This is an idea for #816. - It's still work in progress. - It's based on minimal API + something - There's no public API (not the goal of this PR)
- Loading branch information
Showing
10 changed files
with
246 additions
and
11 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,22 @@ | ||
{ | ||
"name": "53_islands", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "waku dev", | ||
"build": "waku build", | ||
"start": "waku start" | ||
}, | ||
"dependencies": { | ||
"react": "19.0.0", | ||
"react-dom": "19.0.0", | ||
"react-server-dom-webpack": "19.0.0", | ||
"waku": "0.21.16" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "19.0.7", | ||
"@types/react-dom": "19.0.3", | ||
"typescript": "5.7.3" | ||
} | ||
} |
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,34 @@ | ||
import { Slot } from 'waku/minimal/client'; | ||
|
||
import { Counter } from './Counter'; | ||
|
||
const App = ({ name }: { name: string }) => { | ||
return ( | ||
<html> | ||
<head> | ||
<title>Waku</title> | ||
</head> | ||
<body> | ||
<div | ||
style={{ border: '3px red dashed', margin: '1em', padding: '1em' }} | ||
> | ||
<h1>Hello {name}!!</h1> | ||
<h3>This is a static server component.</h3> | ||
<Slot id="Dynamic" unstable_fallback={<p>Loading...</p>}> | ||
<MyCounter /> | ||
</Slot> | ||
<div>{new Date().toISOString()}</div> | ||
</div> | ||
</body> | ||
</html> | ||
); | ||
}; | ||
|
||
const MyCounter = () => ( | ||
<> | ||
<h4>Counter</h4> | ||
<Counter /> | ||
</> | ||
); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
|
||
export const Counter = () => { | ||
const [count, setCount] = useState(0); | ||
return ( | ||
<div style={{ border: '3px blue dashed', margin: '1em', padding: '1em' }}> | ||
<p>Count: {count}</p> | ||
<button onClick={() => setCount((c) => c + 1)}>Increment</button> | ||
<h3>This is a client component.</h3> | ||
</div> | ||
); | ||
}; |
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 type { ReactNode } from 'react'; | ||
|
||
const Dynamic = async ({ children }: { children: ReactNode }) => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return ( | ||
<div style={{ border: '3px orange dashed', margin: '1em', padding: '1em' }}> | ||
<h3>This is a dynamic server component.</h3> | ||
{children} | ||
<div>{new Date().toISOString()}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dynamic; |
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,66 @@ | ||
import { unstable_defineEntries as defineEntries } from 'waku/minimal/server'; | ||
import { Children, Slot } from 'waku/minimal/client'; | ||
import { unstable_createAsyncIterable as createAsyncIterable } from 'waku/server'; | ||
|
||
import App from './components/App'; | ||
import Dynamic from './components/Dynamic'; | ||
|
||
export default defineEntries({ | ||
handleRequest: async (input, { renderRsc, renderHtml }) => { | ||
if (input.type === 'component') { | ||
if (input.rscPath === '') { | ||
return renderRsc({ | ||
App: <App name={input.rscPath || 'Waku'} />, | ||
}); | ||
} | ||
if (input.rscPath === 'dynamic') { | ||
return renderRsc({ | ||
Dynamic: ( | ||
<Dynamic> | ||
<Children /> | ||
</Dynamic> | ||
), | ||
}); | ||
} | ||
throw new Error('Unexpected rscPath: ' + input.rscPath); | ||
} | ||
if (input.type === 'custom' && input.pathname === '/') { | ||
return renderHtml({ App: <App name="Waku" /> }, <Slot id="App" />, { | ||
rscPath: '', | ||
}); | ||
} | ||
}, | ||
handleBuild: ({ | ||
renderRsc, | ||
renderHtml, | ||
rscPath2pathname, | ||
unstable_generatePrefetchCode, | ||
}) => | ||
createAsyncIterable(async () => { | ||
const moduleIds = new Set<string>(); | ||
const generateHtmlHead = () => | ||
`<script type="module" async>${unstable_generatePrefetchCode( | ||
['dynamic'], | ||
moduleIds, | ||
)}</script>`; | ||
const tasks = [ | ||
async () => ({ | ||
type: 'file' as const, | ||
pathname: rscPath2pathname(''), | ||
body: renderRsc( | ||
{ App: <App name="Waku" /> }, | ||
{ moduleIdCallback: (id) => moduleIds.add(id) }, | ||
), | ||
}), | ||
async () => ({ | ||
type: 'file' as const, | ||
pathname: '/', | ||
body: renderHtml({ App: <App name="Waku" /> }, <Slot id="App" />, { | ||
rscPath: '', | ||
htmlHead: generateHtmlHead(), | ||
}).then(({ body }) => body), | ||
}), | ||
]; | ||
return tasks; | ||
}), | ||
}); |
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 { StrictMode, useEffect } from 'react'; | ||
import { createRoot, hydrateRoot } from 'react-dom/client'; | ||
import { Root, Slot, useRefetch } from 'waku/minimal/client'; | ||
|
||
const DynamicFether = () => { | ||
const refetch = useRefetch(); | ||
useEffect(() => { | ||
refetch('dynamic'); | ||
}, [refetch]); | ||
return null; | ||
}; | ||
|
||
const rootElement = ( | ||
<StrictMode> | ||
<Root> | ||
<DynamicFether /> | ||
<Slot id="App" /> | ||
</Root> | ||
</StrictMode> | ||
); | ||
|
||
if ((globalThis as any).__WAKU_HYDRATE__) { | ||
hydrateRoot(document, rootElement); | ||
} else { | ||
createRoot(document as any).render(rootElement); | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"target": "esnext", | ||
"downlevelIteration": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "bundler", | ||
"skipLibCheck": true, | ||
"noUncheckedIndexedAccess": true, | ||
"exactOptionalPropertyTypes": true, | ||
"types": ["react/experimental"], | ||
"jsx": "react-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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.