Fix share button: ES module namespace was not extensible

window.AtShare was assigned the module namespace object from
import('./share'), which is frozen. share.init.ts then threw
'Cannot add property refresh, object is not extensible', aborting the
click handler so the share button did nothing on every page.

- runtime.ts: spread the namespace into a plain object
- share.init.ts: expose the updater as window.AtShareRefresh
- home.init.ts / stop.init.ts: call AtShareRefresh
- remove the temporary probe marker from StopView

Verified: /?s=at_main_terminal, /stops/:code?q=, /routes/:id, /check/:id
all produce short links and restore state on load (TH and EN).
This commit is contained in:
Bkk1234 committed 2026-10-23 23:26:18 +07:00
1 parent 2fa73f43d9
commit 66d7e235c3
6 files changed
+8 -7

No files matched your search

@@ -47,7 +47,6 @@ export default function StopView() {
<div id="stop-chips" style={{display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 14}} />
</aside>
</section>
<div id="share-probe-marker" />
{/* ปุ่มแชร์หน้านี้ — จำตัวกรองสายรถที่เลือกอยู่ลงลิงก์ */}
<div className="mu-share-row">
<button type="button" className="mu-share-btn" id="share-btn">
+2 -1
View File
@@ -31,7 +31,8 @@ export function ensureRuntime(): Promise<void> {
/* ตัวกลางลิงก์แชร์ — ต้องพร้อมก่อนหน้าไหนจะกดแชร์ */
const share = await import("./share");
(window as unknown as { AtShare?: unknown }).AtShare = share;
/* ต้อง spread — ES module namespace object ไม่ extensible (ใส่ property ใหม่ไม่ได้) */
(window as unknown as { AtShare?: unknown }).AtShare = { ...share };
await import("./ui/share.init");
const w = window as unknown as {
+1 -1
View File
@@ -442,7 +442,7 @@ function nm(o: any, base: string): string {
function refreshShareLink() {
var S = (window as any).AtShare;
if (S && S.refresh) S.refresh();
if (typeof (window as any).AtShareRefresh === 'function') (window as any).AtShareRefresh();
}
initHomeSelectors();
+3 -2
View File
@@ -90,8 +90,9 @@ export {}; /* ทำให้ไฟล์นี้เป็น ES module (runt
status.dataset.msg = msg;
}
/* ให้หน้าอื่นเรียกอัปเดตได้เมื่อตัวกรองเปลี่ยน */
(window as any).AtShare.refresh = function () {
/* ให้หน้าอื่นเรียกอัปเดตได้เมื่อตัวกรองเปลี่ยน
(ห้ามเขียนทับ window.AtShare.refresh — namespace object เป็น read-only) */
(window as any).AtShareRefresh = function () {
if (status && status.dataset.shown) paint(status.dataset.msg || "");
};
+1 -1
View File
@@ -351,7 +351,7 @@ function nm(o: any, base: string): string {
/* จำคำค้นหาลง URL → แชร์/บุ๊กมาร์กได้ตรงสถานะล่าสุด */
var S = (window as any).AtShare;
if (S && S.syncShareState) S.syncShareState({ q: input.value.trim() });
if (S && S.refresh) S.refresh();
if (typeof (window as any).AtShareRefresh === 'function') (window as any).AtShareRefresh();
});
}
restoreFilterFromUrl();