Skip to content

Commit

Permalink
chore(rsc): Add ServerDelayForm to rsc-caching fixture (missing files) (
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jul 31, 2024
1 parent d423d60 commit 09c22f4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.server-delay-form {
padding: 1rem;

label div {
margin-bottom: 4px;
}

input {
margin-right: 4px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from 'node:fs'

import { formAction } from './actions'

import './ServerDelayForm.css'

const ServerDelayForm = () => {
let delay = 0

if (fs.existsSync('settings.json')) {
delay = JSON.parse(fs.readFileSync('settings.json', 'utf8')).delay || 0
}

return (
<div className="server-delay-form">
<form action={formAction}>
<label htmlFor="delay">
<div>Delay ({delay}ms)</div>
<input type="number" id="delay" name="delay" />
</label>
<button type="submit">Set</button>
</form>
</div>
)
}

export default ServerDelayForm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use server'

import fs from 'node:fs'

export async function formAction(formData: FormData) {
console.log(formData.get('delay'))
console.log('cwd', process.cwd())
await fs.promises.writeFile(
'settings.json',
`{ "delay": ${formData.get('delay')} }\n`
)
}

0 comments on commit 09c22f4

Please sign in to comment.