Halaman Sverdle dapat diakses di local development dan preview (http://localhost:4173/we-will-shine/sverdle/), tetapi menampilkan 404 Error ketika diakses di GitHub Pages (https://itif-syuhada.github.io/we-will-shine/sverdle/).
-
Server-side rendering dengan cookies
- File
src/routes/sverdle/+page.server.tsmenggunakan server actions dan cookies export const prerender = falsemencegah halaman di-generate sebagai static HTML
- File
-
GitHub Pages limitation
- GitHub Pages hanya bisa serve static files (HTML, CSS, JS)
- Tidak mendukung server-side runtime (Node.js, cookies, form actions)
-
Missing HTML file
- Karena
prerender = false, filebuild/sverdle/index.htmltidak ter-generate - GitHub Pages menampilkan 404 karena file tidak ada
- Karena
# Sebelum fix - file tidak ada
$ ls build/sverdle/
ls: cannot access 'build/sverdle/': No such file or directory
# Local preview works karena menggunakan Node.js server
$ pnpm run preview # ✅ Berfungsi
# GitHub Pages tidak works karena pure staticHapus file server:
- ❌ Hapus
src/routes/sverdle/+page.server.ts
Buat file config baru:
// src/routes/sverdle/+page.ts
export const prerender = true; // Enable prerendering
export const csr = true; // Enable client-side rendering
export const ssr = false; // Disable server-side renderingSebelum (Server-side):
// +page.server.ts
export const load = ({ cookies }) => {
const game = new Game(cookies.get('sverdle'));
return { ... };
};
export const actions = {
update: async ({ cookies }) => {
// ...
cookies.set('sverdle', game.toString(), { path: '/' });
}
};Sesudah (Client-side):
// +page.svelte
import { browser } from '$app/environment';
import { onMount } from 'svelte';
let game = $state<Game | null>(null);
onMount(() => {
if (browser) {
const saved = localStorage.getItem('sverdle');
game = new Game(saved ?? undefined);
}
});
function saveGame() {
if (browser && game) {
localStorage.setItem('sverdle', game.toString());
}
}Perubahan utama di +page.svelte:
- Remove form actions - tidak lagi menggunakan
<form>denganuse:enhance - Direct event handlers - gunakan
onclick={handler}dan keyboard events - Local state management - state sepenuhnya di client-side dengan Svelte 5 runes
- Browser guards - gunakan
browsercheck dari$app/environment
# Rename file
mv src/routes/sverdle/words.server.ts src/routes/sverdle/words.ts
# Update import di game.ts
- import { words, allowed } from './words.server';
+ import { words, allowed } from './words';Sebelum:
src/routes/sverdle/
├── +page.server.ts ❌ (Server-side, cookies)
├── +page.svelte
├── game.ts
└── words.server.ts
Sesudah:
src/routes/sverdle/
├── +page.ts ✅ (prerender = true)
├── +page.svelte ✅ (client-side only, localStorage)
├── game.ts
└── words.ts ✅ (accessible from client)
Sebelum:
$ pnpm run build
$ ls build/sverdle/
# ❌ Folder tidak ada atau kosongSesudah:
$ pnpm run build
$ ls build/sverdle/
index.html how-to-play/
# ✅ File HTML ter-generate!
$ head build/sverdle/index.html
<!doctype html>
<html lang="en">
<head>...</head>
<body>...</body>
</html>
# ✅ Full HTML prerendered!Setup Playwright untuk E2E testing:
# Install
pnpm add -D @playwright/test
# Run tests
pnpm run test:e2eTest coverage:
- ✅ Navigation ke halaman sverdle
- ✅ Game loads correctly
- ✅ Keyboard input functionality
- ✅ Click keyboard buttons
- ✅ Backspace removes letters
- ✅ Enter button enable/disable logic
- ✅ localStorage persistence
- ✅ Restart game functionality
# .github/workflows/deploy.yml
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps chromium
- name: Run tests
run: pnpm run test
- name: Run E2E tests
run: pnpm run test:e2e
- name: Build
run: pnpm run buildSekarang setiap deployment akan:
- ✅ Run unit tests
- ✅ Run E2E tests
- ✅ Build static site
- ✅ Deploy ke GitHub Pages
- ✅ Works on GitHub Pages - Static HTML dapat di-serve
- ✅ No server required - Pure client-side
- ✅ Better UX - Instant game state updates (no server round-trips)
- ✅ Offline capable - localStorage works offline
- ✅ Faster - No network requests for game state
- ✅ E2E tested - Confidence in functionality
- No server-side runtime - Hanya static files
- No cookies from server - Gunakan localStorage
- No form actions - Gunakan client-side JS
- Must prerender - Set
prerender = true
- ✅ Always prerender pages untuk GitHub Pages
- ✅ Use localStorage untuk client state
- ✅ Test with build + preview sebelum deploy
- ✅ Verify HTML files exist di folder build
- ✅ Add E2E tests untuk confidence
Status: ✅ RESOLVED
Tanggal Fix: 13 Oktober 2025
Verified:
- ✅ Local build & preview
- ✅ E2E tests passing
- 🔄 Pending: Verifikasi di GitHub Pages setelah push