feat(pwa): harden the auto-update chain and add a version tool

- ui/pwa.js: register with updateViaCache:'none', check for updates on load, every
  30 min, on tab focus and on 'online'; controllerchange reloads the page itself but
  waits while the user is typing in a form (admin edits survive), retrying on blur/hide
- sw.js: precache the maskable icon; bump VERSION -> 2026.11.24.2
- scripts/bump-version.mjs: bump sw.js VERSION + <meta app-version> together, --check
  fails on drift; wired into
> [email protected] check
> node --check ui/app.js && node --check ui/data.js && node --check ui/router.js && node --check ui/ui.js && node --check ui/pwa.js && node --check ui/views/home.js && node --check ui/views/admin.js && node --check sw.js && node --check server/publish.mjs && node --check server/db.mjs && node --check scripts/bump-version.mjs && node scripts/bump-version.mjs --check

[version] ตรงกันที่ 2026.11.24.2, exposed as
> [email protected] version
> node scripts/bump-version.mjs

[version] ตั้งเป็น 2026.11.24.3 แล้ว (sw.js + index.html)
- README/AGENTS: document the PWA behaviour and the bump workflow

Verified in Chrome: SPA route changes keep timeOrigin and navigation count at 1 (no
reload), a simulated deploy (version bump -> reg.update) replaced the cache from
hobbypj-2026.11.24.1 to .2 with the old cache deleted and the page reloading by
itself, Page.getAppManifest errors: [], and with the network emulated offline the
shell + 6 cards still render while an uncached file fails.
This commit is contained in:
Bkk1234 committed 2026-11-24 14:52:50 +07:00
1 parent 9258cdd09e
commit 634dc3ae3c
7 files changed
+173 -13

No files matched your search

+13
View File
@@ -63,6 +63,19 @@ repo นี้ deploy เป็น **Compose application** บน Dokploy (serve
ถ้าได้ 404 = ยังไม่มี domain ในแท็บ Domains · 502 = container ไม่ขึ้นหรือ port ไม่ตรง (`docker ps` ใน server: `hobbypj-contents-hobbypj-contents-1`)
## PWA: ติดตั้งได้ + อัปเดตแคชเอง (ไม่มี reload ตอนเปลี่ยนหน้า)
- **หน้าเดียว**: hash router (`#/`, `#/admin`) — เปลี่ยนหน้าไม่โหลดใหม่ (`performance.navigation` ไม่เพิ่ม, `timeOrigin` เดิม)
- **ติดตั้งได้**: `manifest.json` (`display: standalone`, ไอคอน 192/512 + maskable) ลิงก์ใน `index.html`
- **ออฟไลน์ได้**: `sw.js` precache shell ไว้ครบ เปิดแบบไม่มีเน็ตยังเห็นรายการ (ข้อมูลจากสำเนา JSON/localStorage)
- **อัปเดตเอง**: `ui/pwa.js` ลงทะเบียนด้วย `updateViaCache: "none"` แล้ว `update()` ตอนเปิดหน้า / ทุก 30 นาที / กลับมาโฟกัสแท็บ / ต่อเน็ตใหม่ · `sw.js` ใช้ `skipWaiting()` + `clients.claim()` → `controllerchange` สั่ง reload หน้าเอง (ชะงักเฉพาะตอนกำลังพิมพ์ในฟอร์ม แล้วทำต่อเมื่อเลิกพิมพ์)
- cache เวอร์ชันเก่าถูกลบใน `activate` → ผู้ใช้ไม่ต้องล้างแคชเอง
```bash
npm run version # bump VERSION (sw.js) + <meta app-version> (index.html) พร้อมกัน
npm run check # มี --check ตรวจสองค่านี้ไม่ให้หลุดกัน
```
## ระบบหลังบ้านทำงานอย่างไร
```