Skip to content

Add RSC Example #188

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 3 commits into from
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
41 changes: 41 additions & 0 deletions examples/rsc-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions examples/rsc-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
7 changes: 7 additions & 0 deletions examples/rsc-app/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
23 changes: 23 additions & 0 deletions examples/rsc-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "rsc-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0",
"next": "15.1.4",
"react-scan": "0.0.53"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19"
}
}
1 change: 1 addition & 0 deletions examples/rsc-app/public/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/rsc-app/public/globe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/rsc-app/public/next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/rsc-app/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/rsc-app/public/window.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions examples/rsc-app/src/app/ReactScan.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';
import { useEffect } from 'react';
import { scan } from 'react-scan';

export default function ReactScan(): JSX.Element {
useEffect(() => {
scan({
enabled: true,
dangerouslyForceRunInProduction: true,
// monitor: {
// url: 'https://localhost:3000/api/scan',
// },
});
}, []);

return <></>;
}
22 changes: 22 additions & 0 deletions examples/rsc-app/src/app/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use server';

import fs from 'fs';
import path from 'path';
import { promisify } from 'util';

const writeFile = promisify(fs.writeFile);

export async function saveData(formData: FormData) {
const file = formData.get('file') as File;
const fileBuffer = await file.arrayBuffer();
const filePath = path.join(`/tmp/${file.name}`);
await writeFile(filePath, Buffer.from(fileBuffer));

const payload = {
email: formData.get('email'),
};

console.log('payload', payload);
Copy link
Collaborator

Choose a reason for hiding this comment

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

🧹

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

kind of intended. Just for immediate confirmation.


return payload;
}
25 changes: 25 additions & 0 deletions examples/rsc-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ReactScan from '@/app/ReactScan';
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={inter.className}>
{children}
<ReactScan />
</body>
</html>
);
}
5 changes: 5 additions & 0 deletions examples/rsc-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import UploadForm from './upload-form';

export default function Home() {
return <UploadForm />;
}
39 changes: 39 additions & 0 deletions examples/rsc-app/src/app/upload-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client';
import { useRef } from 'react';
import { useFormStatus } from 'react-dom';
import { saveData } from './action';

function Submit() {
const { pending } = useFormStatus();
return (
<button disabled={pending}>{pending ? 'Submitting' : 'Submit'}</button>
);
}

export default function UploadForm() {
const formRef = useRef<HTMLFormElement | null>(null);

async function formAction(formData: FormData) {
await saveData(formData);
formRef.current?.reset();
alert('Save success!');
}

return (
<form action={formAction} ref={formRef}>
<h1>Upload Demo</h1>

<div>Email</div>
<input type="email" name="email" required />
<br />
<br />

<div>Select file</div>
<input type="file" name="file" required />
<br />
<br />
<br />
<Submit />
</form>
);
}
27 changes: 27 additions & 0 deletions examples/rsc-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading
Loading