fix(motion): คืนอนิเมชัน reveal ที่หายไป + จดข้อยกเว้นเบราว์เซอร์
สาเหตุ: hydration เขียนทับ class ของ <html> ทำให้ `fx-motion` หลุด และอนิเมชันเดิมผูกกับคลาสนั้นอย่างเดียว → อนิเมชันหายทั้งเว็บ - ผูก "ตัวอนิเมชัน" กับ @media (prefers-reduced-motion: no-preference) (สถานะซ่อนก่อน reveal ยังผูกกับ html.fx-motion เพื่อกันเนื้อหาหายเมื่อปิด JS) - เพิ่ม <MotionBootstrap/> เติมคลาส fx-motion ซ้ำหลัง hydration + ฟังการเปลี่ยน reduced-motion - คืน @keyframes fx-swap-in ที่หลุดไประหว่างแก้ CSS - DESIGN.md: Motion contract สองชั้น + ตารางข้อยกเว้นต่อเบราว์เซอร์ (scrollbar/share/install/blur/ฟอนต์ไทย/ITP) - sw VERSION v2.0.4
This commit is contained in:
1 parent
2eb625c8bc
commit
cfb24b8138
4 files changed
+92
-40
No files matched your search
@@ -124,6 +124,28 @@ function ServiceWorkerSetup() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* เติมคลาส `fx-motion` ซ้ำฝั่ง client
|
||||
*
|
||||
* ทำไมต้องมี: สคริปต์ใน <head> ใส่คลาสนี้ก่อน paint แล้ว แต่พบว่า hydration
|
||||
* เขียนทับ `class` ของ <html> ทำให้คลาสหลุด → เนื้อหาที่ควร "ค่อย ๆ โผล่"
|
||||
* กลายเป็นโผล่ทันที (อนิเมชันหาย) · effect นี้รันหลัง hydration จึงเติมกลับให้เสถียร
|
||||
* ตัวอนิเมชันเองผูกกับ `@media (prefers-reduced-motion: no-preference)` แล้ว
|
||||
* จึงยังทำงานได้แม้คลาสหลุด (คลาสมีหน้าที่แค่ "ซ่อนก่อน reveal" ไม่ให้กระพริบ)
|
||||
*/
|
||||
function MotionBootstrap() {
|
||||
useEffect(() => {
|
||||
const query = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
const sync = () => {
|
||||
document.documentElement.classList.toggle("fx-motion", !query.matches);
|
||||
};
|
||||
sync();
|
||||
query.addEventListener("change", sync);
|
||||
return () => query.removeEventListener("change", sync);
|
||||
}, []);
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function Root() {
|
||||
const [queryClient] = useState(() => createAgentNativeQueryClient());
|
||||
const { content, localeFromUrl, shareOrigin } =
|
||||
@@ -141,6 +163,7 @@ export default function Root() {
|
||||
<AppProviders queryClient={queryClient}>
|
||||
<DbSyncSetup />
|
||||
<ServiceWorkerSetup />
|
||||
<MotionBootstrap />
|
||||
<AppLayout>
|
||||
<Outlet />
|
||||
</AppLayout>
|
||||
|
||||
Reference in new issue
Block a user