Skip to content

Commit 4799dde

Browse files
authored
refactor: Rename sandbox to runtime and fix terminal hook (#130)
* fix(hooks): refactor useTerminal to avoid synchronous setState warning * fix(hooks): remove unused onError variable * chore(infra): rename sandbox directory to runtime
1 parent 3411b02 commit 4799dde

7 files changed

Lines changed: 21 additions & 34 deletions

File tree

.github/workflows/build-runtime.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ on:
66
branches: [main, master]
77
types: [opened, synchronize, reopened]
88
paths:
9-
- "sandbox/**"
9+
- "runtime/**"
1010
- ".github/workflows/build-runtime.yml"
11-
- "!sandbox/*.md"
11+
- "!runtime/*.md"
1212
push:
1313
branches: [main, master]
1414
paths:
15-
- "sandbox/**"
15+
- "runtime/**"
1616
- ".github/workflows/build-runtime.yml"
17-
- "!sandbox/*.md"
17+
- "!runtime/*.md"
1818

1919
permissions:
2020
pull-requests: write
@@ -88,8 +88,8 @@ jobs:
8888
id: docker-build
8989
uses: docker/build-push-action@v6
9090
with:
91-
context: ./sandbox
92-
file: ./sandbox/Dockerfile
91+
context: ./runtime
92+
file: ./runtime/Dockerfile
9393
labels: ${{ steps.meta.outputs.labels }}
9494
platforms: linux/amd64
9595
tags: ${{ steps.meta.outputs.tags }}

hooks/use-terminal.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,22 @@ export function useTerminal(options: UseTerminalOptions): UseTerminalReturn {
4747
reconnectDelay = 3000,
4848
onConnected,
4949
onDisconnected,
50-
onError,
5150
} = options
5251

5352
const [status, setStatus] = useState<'disconnected' | 'connecting' | 'connected' | 'error'>(
54-
'disconnected'
53+
ttydUrl ? 'connecting' : 'disconnected'
5554
)
56-
const [wsUrl, setWsUrl] = useState<string | null>(null)
55+
const [wsUrl, setWsUrl] = useState<string | null>(ttydUrl ?? null)
56+
const [prevTtydUrl, setPrevTtydUrl] = useState(ttydUrl)
57+
58+
if (ttydUrl !== prevTtydUrl) {
59+
setPrevTtydUrl(ttydUrl)
60+
setWsUrl(ttydUrl ?? null)
61+
setStatus(ttydUrl ? 'connecting' : 'disconnected')
62+
}
5763
const reconnectTimeoutRef = useRef<NodeJS.Timeout | null>(null)
5864
const shouldReconnectRef = useRef(true)
5965

60-
// Parse ttyd URL and prepare WebSocket URL
61-
useEffect(() => {
62-
if (!ttydUrl) {
63-
setWsUrl(null)
64-
setStatus('disconnected')
65-
return
66-
}
67-
68-
try {
69-
// ttydUrl already includes the token as query parameter
70-
setWsUrl(ttydUrl)
71-
setStatus('connecting')
72-
} catch (error) {
73-
console.error('[useTerminal] Invalid ttyd URL:', error)
74-
setStatus('error')
75-
onError?.(error as Error)
76-
}
77-
}, [ttydUrl, onError])
78-
7966
// Handle connection status callbacks
8067
const handleConnected = useCallback(() => {
8168
setStatus('connected')
File renamed without changes.
File renamed without changes.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Users can manually expose these ports if needed:
149149
The image is automatically built via GitHub Actions workflow when:
150150
- Pull requests are opened (validation only, no push)
151151
- Changes are pushed to `main` or `master` branch
152-
- Changes are detected in `sandbox/` directory
152+
- Changes are detected in `runtime/` directory
153153
- Manually triggered via workflow dispatch
154154

155155
**Workflow File**: `.github/workflows/build-runtime.yml`
@@ -169,14 +169,14 @@ The image is automatically built via GitHub Actions workflow when:
169169
### Local Build (Single Architecture)
170170

171171
```bash
172-
cd sandbox
172+
cd runtime
173173
docker build -t fullstack-web-runtime:local .
174174
```
175175

176176
### Local Multi-Architecture Build
177177

178178
```bash
179-
cd sandbox
179+
cd runtime
180180
docker buildx build \
181181
--platform linux/amd64,linux/arm64 \
182182
-t fullstack-web-runtime:local \
@@ -210,7 +210,7 @@ Set these in repository settings (Settings → Secrets and variables → Actions
210210
### Directory Structure
211211

212212
```
213-
sandbox/
213+
runtime/
214214
├── Dockerfile # Multi-stage Docker build
215215
├── entrypoint.sh # Container startup script
216216
├── .bashrc # Shell configuration with custom prompt
@@ -228,7 +228,7 @@ sandbox/
228228

229229
```bash
230230
# Build locally
231-
cd sandbox
231+
cd runtime
232232
docker build -t test-runtime .
233233

234234
# Test web terminal
@@ -408,7 +408,7 @@ We welcome contributions! Please follow these steps:
408408

409409
1. Fork the repository
410410
2. Create a feature branch (`git checkout -b feature/my-feature`)
411-
3. Make your changes to `sandbox/` directory
411+
3. Make your changes to `runtime/` directory
412412
4. Test locally with `docker build`
413413
5. Commit your changes (`git commit -m 'feat: Add new feature'`)
414414
6. Push to your fork (`git push origin feature/my-feature`)

0 commit comments

Comments
 (0)