Skip to content

Commit

Permalink
breaking: multiple elements in a single response (#124)
Browse files Browse the repository at this point in the history
* wip: examples 01 dev

* hack with _ssr, not ideal though

* examples 02

* simplify waku/client usage

* example 03

* example 04

* improve example 04

* examples 05

* example 06

* fix example 06

* support children

* wip: waku/router, which is tough one

* rename from Server to Slot

* wip: fix router

* refactor consistent names

* wip: fix router

* add react hooks eslint plugin

* improve prefetched

* fix example 08

* fix example 09

* fix test

* wip: ssr config

* fix ex 06

* fix waku/router

* wip: website

* fix interleaveHtmlSnippets

* remove unstable_rootDir

* fix router build

* fix explicit index path (suboptimal?)

* this should be a proper fix

* website: use path prop #84

* fix action and improve example/06

* re-design router input string and allow client cache control

* update website

* make initialInput prop optional

* use "" for initial input for simplicity

* fix and a workaround for empty input string, seems suboptimal..
  • Loading branch information
dai-shi committed Sep 11, 2023
1 parent 755b6da commit bf9a0fb
Show file tree
Hide file tree
Showing 83 changed files with 1,377 additions and 1,097 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier"
Expand Down
2 changes: 1 addition & 1 deletion examples/01_counter/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Counter } from "./Counter.js";

const App = ({ name = "Anonymous" }) => {
const App = ({ name }: { name: string }) => {
return (
<div style={{ border: "3px red dashed", margin: "1em", padding: "1em" }}>
<h1>Hello {name}!!</h1>
Expand Down
30 changes: 0 additions & 30 deletions examples/01_counter/src/entries.ts

This file was deleted.

34 changes: 34 additions & 0 deletions examples/01_counter/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { lazy } from "react";

import { defineEntries } from "waku/server";

const App = lazy(() => import("./components/App.js"));

export default defineEntries(
// renderEntries
async (input) => {
return {
App: <App name={input || "Waku"} />,
};
},
// getBuildConfig
async () => {
return {
"/": {
entries: [[""]],
},
};
},
// getSsrConfig
async () => ({
getInput: (pathStr) => {
switch (pathStr) {
case "/":
return "";
default:
return null;
}
},
filter: (elements) => elements.App,
}),
);
7 changes: 4 additions & 3 deletions examples/01_counter/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { serve } from "waku/client";
import { Root, Slot } from "waku/client";

const App = serve<{ name: string }>("App");
const rootElement = (
<StrictMode>
<App name="Waku" />
<Root>
<Slot id="App" />
</Root>
</StrictMode>
);

Expand Down
2 changes: 1 addition & 1 deletion examples/02_async/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Suspense } from "react";

import { Counter } from "./Counter.js";

const App = ({ name = "Anonymous" }) => {
const App = ({ name }: { name: string }) => {
return (
<div style={{ border: "3px red dashed", margin: "1em", padding: "1em" }}>
<h1>Hello {name}!!</h1>
Expand Down
30 changes: 0 additions & 30 deletions examples/02_async/src/entries.ts

This file was deleted.

34 changes: 34 additions & 0 deletions examples/02_async/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { lazy } from "react";

import { defineEntries } from "waku/server";

const App = lazy(() => import("./components/App.js"));

export default defineEntries(
// renderEntries
async (input) => {
return {
App: <App name={input || "Waku"} />,
};
},
// getBuildConfig
async () => {
return {
"/": {
entries: [[""]],
},
};
},
// getSsrConfig
async () => ({
getInput: (pathStr) => {
switch (pathStr) {
case "/":
return "";
default:
return null;
}
},
filter: (elements) => elements.App,
}),
);
7 changes: 4 additions & 3 deletions examples/02_async/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
import { serve } from "waku/client";
import { Root, Slot } from "waku/client";

const App = serve<{ name: string }>("App");
const rootElement = (
<StrictMode>
<App name="Waku" />
<Root>
<Slot id="App" />
</Root>
</StrictMode>
);

Expand Down
4 changes: 3 additions & 1 deletion examples/03_promise/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ReactNode } from "react";
import { Counter } from "./Counter.js";

const App = ({ name = "Anonymous" }) => {
const App = ({ name, children }: { name: string; children: ReactNode }) => {
const delayedMessage = new Promise<string>((resolve) => {
setTimeout(() => resolve("Hello from server!"), 2000);
});
Expand All @@ -9,6 +10,7 @@ const App = ({ name = "Anonymous" }) => {
<h1>Hello {name}!!</h1>
<h3>This is a server component.</h3>
<Counter delayedMessage={delayedMessage} />
{children}
</div>
);
};
Expand Down
30 changes: 0 additions & 30 deletions examples/03_promise/src/entries.ts

This file was deleted.

39 changes: 39 additions & 0 deletions examples/03_promise/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { lazy } from "react";

import { defineEntries } from "waku/server";
import { Children } from "waku/client";

const App = lazy(() => import("./components/App.js"));

export default defineEntries(
// renderEntries
async (input) => {
return {
App: (
<App name={input || "Waku"}>
<Children />
</App>
),
};
},
// getBuildConfig
async () => {
return {
"/": {
entries: [[""]],
},
};
},
// getSsrConfig
async () => ({
getInput: (pathStr) => {
switch (pathStr) {
case "/":
return "";
default:
return null;
}
},
filter: (elements) => elements.App,
}),
);
9 changes: 6 additions & 3 deletions examples/03_promise/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { serve } from "waku/client";
import { Root, Slot } from "waku/client";

const App = serve<{ name: string }>("App");
const rootElement = (
<StrictMode>
<App name="Waku" />
<Root>
<Slot id="App">
<h3>A client element</h3>
</Slot>
</Root>
</StrictMode>
);

Expand Down
2 changes: 1 addition & 1 deletion examples/04_callserver/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type ServerFunction<T> = T extends (...args: infer A) => infer R
? (...args: A) => Promise<R>
: never;

const App = ({ name = "Anonymous" }) => {
const App = ({ name }: { name: string }) => {
return (
<div style={{ border: "3px red dashed", margin: "1em", padding: "1em" }}>
<h1>Hello {name}!!</h1>
Expand Down
2 changes: 1 addition & 1 deletion examples/04_callserver/src/components/Counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState, useTransition } from "react";
export const Counter = ({
greet,
}: {
greet: (name: string) => string | Promise<string>;
greet: (name: string) => Promise<string>;
}) => {
const [count, setCount] = useState(0);
const [text, setText] = useState<string | Promise<string>>("");
Expand Down
30 changes: 0 additions & 30 deletions examples/04_callserver/src/entries.ts

This file was deleted.

34 changes: 34 additions & 0 deletions examples/04_callserver/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { lazy } from "react";

import { defineEntries } from "waku/server";

const App = lazy(() => import("./components/App.js"));

export default defineEntries(
// renderEntries
async (input) => {
return {
App: <App name={input || "Waku"} />,
};
},
// getBuildConfig
async () => {
return {
"/": {
entries: [[""]],
},
};
},
// getSsrConfig
async () => ({
getInput: (pathStr) => {
switch (pathStr) {
case "/":
return "";
default:
return null;
}
},
filter: (elements) => elements.App,
}),
);
7 changes: 4 additions & 3 deletions examples/04_callserver/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { serve } from "waku/client";
import { Root, Slot } from "waku/client";

const App = serve<{ name: string }>("App");
const rootElement = (
<StrictMode>
<App name="Waku" />
<Root>
<Slot id="App" />
</Root>
</StrictMode>
);

Expand Down
Loading

1 comment on commit bf9a0fb

@vercel
Copy link

@vercel vercel bot commented on bf9a0fb Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

waku – ./

waku.vercel.app
waku-git-main-daishi.vercel.app
waku-daishi.vercel.app
waku.gg
www.waku.gg

Please sign in to comment.