Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: updates #389

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ visit [waku.gg](https://waku.gg) or `npm create waku@latest`

**Waku** _(wah-ku)_ or **わく** means “framework” in Japanese. As the minimal React framework, it aims to accelerate the work of developers at startups and agencies building small to medium-sized React projects. These include marketing websites, light ecommerce, and web applications.

We recommend other frameworks for heavy ecommerce or enterprise applications. Waku is a lightweight alternative designed to bring a fun developer experience to the modern React server components era. Yes, let’s make React development fun again!
We recommend other frameworks for heavy ecommerce or enterprise applications. Waku is a lightweight alternative designed to bring a fun developer experience to the modern React server components era. Yes, let’s make React development fun!

> Waku is in rapid development and some features are currently missing. Please try it on non-production projects and report any issues you may encounter. Expect that there will be some breaking changes on the road towards a stable v1 release. Contributors are welcome.

Expand All @@ -37,7 +37,7 @@ Future versions of Waku may provide additional APIs to abstract away some of the

#### Server components

Waku follows React conventions including support for [server components](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md) and [server actions](https://react.dev/reference/react/use-server). Server components can be made async to securely perform server-side logic and data fetching, but have no interactivity.
Waku follows React conventions including [server components](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md) and [server actions](https://react.dev/reference/react/use-server). Server components can be made async and can securely perform server-side logic and data fetching. They have no interactivity since they run exclusively on the server.

```tsx
// server component
Expand All @@ -54,7 +54,7 @@ export const StorePage = async () => {

#### Client components

Client components are specified with the `'use client'` directive at the top of the file. They can use all traditional React features such as state, effects, and event handlers.
A `'use client'` directive placed at the top of a file will create a server-client boundary when the module is imported into a server component. All components imported below the boundary will be hydrated and run in the browser. They can use all traditional React features such as state, effects, and event handlers.

```tsx
// client component
Expand All @@ -74,13 +74,17 @@ export const Counter = () => {
};
```

#### Shared components

Simple React components that [meet all of the rules](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md#sharing-code-between-server-and-client) of both server and client components can be imported to either server or client components without affecting the server-client boundary.

#### Weaving patterns

Server components can import client components and doing so will create a server-client boundary. Client components cannot import server components, but they can accept server components as props such as `children`.

#### Server-side rendering

Waku provides static prerendering (SSG) or server-side rendering (SSR) options for layouts and pages including their server _and_ client components. Client components are then hydrated in the browser to support events, effects, and so on.
Waku provides static prerendering (SSG) or server-side rendering (SSR) options for layouts and pages including both their server and client components.

#### Further reading

Expand All @@ -90,7 +94,9 @@ To learn more about the modern React architecture, we recommend [Making Sense of

The entry point for routing in Waku projects is `./src/entries.tsx`. Export the `createPages` function to create your layouts and pages programatically.

Both `createLayout` and `createPage` accept a configuration object to specify the route path, React component, and render method (`'static'` for SSG or `'dynamic'` for SSR). Layout components must accept a `children` prop.
Both `createLayout` and `createPage` accept a configuration object to specify the route path, React component, and render method. Waku currently supports two options: `'static'` for static prerendering (SSG) or `'dynamic'` for server-side rendering (SSR).
Copy link
Owner

Choose a reason for hiding this comment

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

What's not describe but technically interesting is that it works without SSR.
In that case, 'static' means static RSC and 'dynamic' means dynamic RSC. Even with SSR, the subsequent updates are RSC only and static/dynamic matter.

It's a hard concept and may not fit in README though.


For example you can statically prerender a global header and footer in the root layout at build time, but dynamically render the rest of a home page at request time for personalized user experiences.

```tsx
// ./src/entries.tsx
Expand Down
90 changes: 90 additions & 0 deletions docs/minimal-api.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
slug: minimal-api
title: Minimal API
Copy link
Owner

Choose a reason for hiding this comment

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

description: The minimal Waku API for library authors.
---

## Minimal

### Server API

To use React Server Components in Waku, you need to create an `entries.ts` file in the project root directory with a `renderEntries` function that returns a server component module.

```tsx
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'} />,
};
},
);
```

The `id` parameter is the ID of the React Server Component that you want to load on the server. You specify the RSC ID from the client.

### Client API

To render a React Server Component on the client, you can use the `Root` and `Slot` components from `waku/client` with the RSC ID to create a wrapper component.

```tsx
import { createRoot } from 'react-dom/client';
import { Root, Slot } from 'waku/client';

const rootElement = (
<StrictMode>
<Root>
<Slot id="App" />
</Root>
</StrictMode>
);

createRoot(document.getElementById('root')!).render(rootElement);
```

The `initialInput` prop can be passed to the `Root` Component, overriding the default input which is `""`. You can also re-render a React Server Component with new input.

```tsx
import { useRefetch } from 'waku/client';

const Component = () => {
const refetch = useRefetch();
const handleClick = () => {
refetch('...');
};
// ...
};
```

### Additional Server API

In addition to the `renderEntries` function, you can also optionally specify `getBuildConfig` function in
`entries.ts`.

```tsx
import { defineEntries } from 'waku/server';

export default defineEntries(
// renderEntries
async (input) => {
return {
App: <App name={input || 'Waku'} />,
};
},
// getBuildConfig
async () => {
return {
'/': {
entries: [['']],
},
};
},
);
```

The `getBuildConfig` function is used for build-time optimization. It renders React Server Components during the build process to produce the output that will be sent to the client. Note that rendering here means to produce RSC payload not HTML content.
4 changes: 3 additions & 1 deletion packages/website/contents/post-001.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ The API is designed to be simple and extensible. We implement a reference router

We’re thankful that Vercel has helped sponsor Waku on GitHub. We’ve made it possible to deploy Waku to Vercel.

Vercel supports the deployment of any frontend framework. We use their [Build Output API](https://vercel.com/docs/build-output-api/v3) to produce output from Waku which can be deployed to Vercel. Specifically, we use two features of the API to power the Waku’s RSC capabilities:
Vercel supports the deployment of any frontend framework. We use their [Build Output API](https://vercel.com/docs/build-output-api/v3) to produce output from Waku which can be deployed to Vercel.

Specifically, we use two features of the API to power the Waku’s RSC capabilities:

- **Overrides Configuration:** Allows customization of the “content-type” header, which is required for the client to properly handle RSC payloads.

Expand Down
2 changes: 1 addition & 1 deletion packages/website/contents/post-002.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ release: 0.19
date: 2024/1/16
---

Until now, [Waku](https://waku.gg) has been helpful as a reference implementation for library authors curious about [React server components](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md). Today's v0.19 release marks the shift towards building Waku into a production-ready React framework. It's designed for startups and agencies seeking a lightweight alternative for small to medium-sized React projects. We want to make React development fun again!
Until now, [Waku](https://waku.gg) has been helpful as a reference implementation for library authors curious about [React server components](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md). Today's v0.19 release marks the shift towards building Waku into a production-ready React framework. It's designed for startups and agencies seeking a lightweight alternative for small to medium-sized React projects. We want to make React development fun!

The first building block is the new `createPages` function, a low-level routing API which allows Waku developers to create layouts and pages programatically. Both static prerendering (SSG) and server-side rendering (SSR) options are available and are selected at the layout and page level.

Expand Down
Loading