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

feat: Add Example / SSR Target selection based deployment target #481

Closed
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
2 changes: 2 additions & 0 deletions examples/15_ssr_target/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
24 changes: 24 additions & 0 deletions examples/15_ssr_target/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "waku-context-broken",
"version": "0.0.0",
"type": "module",
"private": true,
"scripts": {
"dev": "waku dev --with-ssr",
"build": "waku build --with-ssr",
"start": "waku start --with-ssr"
},
"dependencies": {
"react": "18.3.0-canary-4b2a1115a-20240202",
"react-dom": "18.3.0-canary-4b2a1115a-20240202",
"react-server-dom-webpack": "18.3.0-canary-4b2a1115a-20240202",
"react-textarea-autosize": "^8.5.3",
"waku": "0.19.2"
},
"devDependencies": {
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"typescript": "5.3.3",
"vite": "^5.0.12"
}
}
Binary file added examples/15_ssr_target/public/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions examples/15_ssr_target/src/components/MyTextarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use client';
import TextareaAutosize from 'react-textarea-autosize';

export const MyTextarea = () => {
return (
<div>
<TextareaAutosize />
</div>
);
};
28 changes: 28 additions & 0 deletions examples/15_ssr_target/src/components/error-boundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component } from 'react';
import type { ReactNode, FunctionComponent } from 'react';

interface Props {
fallback: (error: unknown) => ReactNode;
children: ReactNode;
}

class ErrorBoundaryClass extends Component<Props, { error?: unknown }> {
constructor(props: Props) {
super(props);
this.state = {};
}

static getDerivedStateFromError(error: unknown) {
return { error };
}

render() {
if ('error' in this.state) {
return this.props.fallback(this.state.error);
}
return this.props.children;
}
}

export const ErrorBoundary =
ErrorBoundaryClass as unknown as FunctionComponent<Props>;
18 changes: 18 additions & 0 deletions examples/15_ssr_target/src/entries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createPages } from 'waku';

import { RootLayout } from './templates/root-layout.js';
import { HomePage } from './templates/home-page.js';

export default createPages(async ({ createPage, createLayout }) => {
createLayout({
render: 'static',
path: '/',
component: RootLayout,
});

createPage({
render: 'static',
path: '/',
component: HomePage,
});
});
19 changes: 19 additions & 0 deletions examples/15_ssr_target/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { StrictMode } from 'react';
import { createRoot, hydrateRoot } from 'react-dom/client';
import { Router } from 'waku/router/client';

import { ErrorBoundary } from './components/error-boundary.js';

const rootElement = (
<StrictMode>
<ErrorBoundary fallback={(error) => <h1>{String(error)}</h1>}>
<Router />
</ErrorBoundary>
</StrictMode>
);

if (import.meta.env.WAKU_HYDRATE) {
hydrateRoot(document.body, rootElement);
} else {
createRoot(document.body).render(rootElement);
}
24 changes: 24 additions & 0 deletions examples/15_ssr_target/src/templates/home-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MyTextarea } from '../components/MyTextarea.js';

export const HomePage = async () => {
const data = await getData();

return (
<div>
<title>{data.title}</title>
<h1 className="text-4xl font-bold tracking-tight">{data.headline}</h1>
<p>{data.body}</p>
<MyTextarea />
</div>
);
};

const getData = async () => {
const data = {
title: 'Waku',
headline: 'Waku',
body: 'Hello world!',
};

return data;
};
26 changes: 26 additions & 0 deletions examples/15_ssr_target/src/templates/root-layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ReactNode } from 'react';

type RootLayoutProps = { children: ReactNode };

export const RootLayout = async ({ children }: RootLayoutProps) => {
const data = await getData();

return (
<div id="__waku" className="font-['Nunito']">
<meta property="description" content={data.description} />
<link rel="icon" type="image/png" href={data.icon} />
<main className="flex min-h-svh items-center justify-center *:min-h-64 *:min-w-64">
{children}
</main>
</div>
);
};

const getData = async () => {
const data = {
description: 'An internet website!',
icon: '/images/favicon.png',
};

return data;
};
14 changes: 14 additions & 0 deletions examples/15_ssr_target/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"strict": true,
"target": "esnext",
"downlevelIteration": true,
"esModuleInterop": true,
"module": "nodenext",
"skipLibCheck": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"types": ["react/experimental"],
"jsx": "react-jsx"
}
}
Loading
Loading