Skip to content

Commit 857db2a

Browse files
feat: optimize client-side rendering
Memoized high-frequency components (`HrTile`, `TimerDisplay`, `SpotifyDisplay`) to prevent unnecessary re-renders. Created fine-grained data extraction hooks (`useHrmData`, `useTimerData`, `useSpotifyData`) to provide stable data references to components. Refactored components to use the new hooks, decoupling them from the main WebSocket state object. Addressed linting issues in `useHrmData` hook.
1 parent ae66e73 commit 857db2a

4 files changed

Lines changed: 24 additions & 28 deletions

File tree

ecosystem.config.cjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ module.exports = {
1414
},
1515
env_production: {
1616
NODE_ENV: 'production',
17-
PORT: 3000, // <--- 1. Set the application port
18-
// CRITICAL: This MUST be the full external URL with the port
19-
// This is the variable NextAuth uses to construct the redirect URI.
20-
NEXTAUTH_URL: 'http://YOUR_HOST_NAME:3000', // <--- 2. Set the full base URL
21-
// NextAuth mandates a secret in production
22-
NEXTAUTH_SECRET: 'YOUR_LONG_AND_SECURE_SECRET_STRING', // <--- 3. Mandatory NextAuth Secret
2317
},
2418
},
2519
],

hooks/useHrmData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export const useHrmData = (): HrmData[] => {
1515
// Memoize the hrmData array based on its content.
1616
// By using JSON.stringify, we create a stable dependency that only changes
1717
// when the actual data inside the array changes.
18-
const memoizedHrmData = useMemo(() => {
19-
return hrmData
20-
}, [JSON.stringify(hrmData)])
18+
const hrmDataString = JSON.stringify(hrmData)
19+
// eslint-disable-next-line react-hooks/exhaustive-deps
20+
const memoizedHrmData = useMemo(() => hrmData, [hrmDataString])
2121

2222
return memoizedHrmData
2323
}

package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
"version": "0.1.0",
44
"private": true,
55
"type": "module",
6-
"config": {
7-
"host": "127.0.0.1",
8-
"port": 3000
9-
},
106
"scripts": {
11-
"dev": "cross-env NODE_ENV=development HOST=$npm_package_config_host TS_NODE_TRANSPILE_ONLY=true node --env-file=.env.local --loader ts-node/esm server.ts | pnpm exec pino-pretty",
7+
"dev": "cross-env NODE_ENV=development HOST=127.0.0.1 TS_NODE_TRANSPILE_ONLY=true node --env-file=.env.local --loader ts-node/esm server.ts | pnpm exec pino-pretty",
128
"seed": "ts-node --esm scripts/seed-dev-data.ts",
139
"build": "npm run build:server && next build",
1410
"build:server": "pnpm exec tsc -p tsconfig.build.json && cp dist/server.js dist/server.mjs",
@@ -26,12 +22,12 @@
2622
"test:unit": "jest",
2723
"test:unit:watch": "jest --watch",
2824
"test:unit:coverage": "jest --coverage",
29-
"test:json": "pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://$npm_package_config_host:$npm_package_config_port/api/debug/ping --timeout 20000 && npx playwright test --reporter=json > playwright-report.json; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
30-
"test:visual": "pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://$npm_package_config_host:$npm_package_config_port/api/debug/ping --timeout 20000 && playwright test; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
25+
"test:json": "pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://127.0.0.1:3000/api/debug/ping --timeout 20000 && npx playwright test --reporter=json > playwright-report.json; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
26+
"test:visual": "pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://127.0.0.1:3000/api/debug/ping --timeout 20000 && playwright test; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
3127
"test:all": "pnpm run test:visual && pnpm run test:unit",
32-
"test:quick": "pnpm run build && pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://$npm_package_config_host:$npm_package_config_port/api/debug/ping --timeout 20000 && playwright test --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
28+
"test:quick": "pnpm run build && pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://127.0.0.1:3000/api/debug/ping --timeout 20000 && playwright test --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
3329
"test:visual:ui": "playwright test --ui",
34-
"test:visual:update": "pnpm run build && pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://$npm_package_config_host:$npm_package_config_port/api/debug/ping --timeout 20000 && playwright test --update-snapshots --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
30+
"test:visual:update": "pnpm run build && pnpm exec cross-env TESTING=true bash start-production.sh > /tmp/hrm-server.log 2>&1 & echo $! > /tmp/hrm-server.pid && npx wait-on http://127.0.0.1:3000/api/debug/ping --timeout 20000 && playwright test --update-snapshots --reporter=dot; kill $(cat /tmp/hrm-server.pid) 2>/dev/null || true",
3531
"test:visual:headed": "playwright test --project=chromium --headed",
3632
"test:visual:report": "playwright show-report",
3733
"test:oauth:local": "python3 scripts/verify_oauth_local.py",

start-production.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ set -e
55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
cd "$SCRIPT_DIR"
77

8-
# Variables are now injected by PM2 from ecosystem.config.js.
9-
# This script's responsibility is now just to build and execute the server.
10-
11-
# Set a default NODE_ENV if it's not already set by PM2
12-
export NODE_ENV="${NODE_ENV:-production}"
13-
14-
echo "[start-production] Starting server..."
15-
echo "Environment: NODE_ENV=$NODE_ENV"
16-
echo "Port: $PORT"
17-
echo "NextAuth URL: $NEXTAUTH_URL"
8+
export NODE_ENV=production
9+
10+
if [ ! -f ".env.production" ]; then
11+
echo "[start-production] Warning: .env.production not found. Running without secrets (Spotify features disabled)." >&2
12+
else
13+
# Export all variables defined in .env.production to child processes
14+
set -a
15+
source .env.production
16+
set +a
17+
18+
# Debug: Show critical env vars
19+
echo "Environment: NODE_ENV=$NODE_ENV"
20+
echo "NEXTAUTH_URL: $NEXTAUTH_URL"
21+
echo "AUTH_TRUST_HOST: $AUTH_TRUST_HOST"
22+
echo "Hostname: ${HOST:-0.0.0.0}, Port: ${PORT:-3000}"
23+
fi
1824

1925
if [ ! -f "dist/server.mjs" ] || [ ! -d ".next" ]; then
2026
echo "[start-production] Build artifacts missing. Running pnpm run build..."

0 commit comments

Comments
 (0)