From 2370cac3947b8e8781e6e7feb6eee397576bfc66 Mon Sep 17 00:00:00 2001 From: Yuki Kobayashi <137767097+aster-void@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:01:16 +0900 Subject: [PATCH] Fix zod error (#506) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # PRの概要 zod エラーの解消 closes #370 ## 具体的な変更内容 ## 影響範囲 ## 動作要件 ## 補足 ## レビューリクエストを出す前にチェック! - [ ] 改めてセルフレビューしたか - [ ] 手動での動作検証を行ったか - [ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [ ] わかりやすいPRになっているか --- web/bun.lockb | Bin 118736 -> 119070 bytes web/package.json | 1 + web/src/api/chat/chat.ts | 19 ++++++++++++++++--- web/src/hooks/useSWR.ts | 22 +++++++++++++++------- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/web/bun.lockb b/web/bun.lockb index 3a9e6d19b0f2885328bd7c3021e327483a07031e..870ae427d6ecd0b62c08df27cfd69eff83abf329 100755 GIT binary patch delta 14231 zcmeHOc~lg~*6$h_WmH^27!X-p5D{c`K#&o4Gw$063WA7=qC7UVF|ty^`gs;hgt zdoHZ0wR&Bxcm2G7NERnMW%)NQC@M_3zv+aXM|Q16PY&$ccs6;*l4bLD-&lNsNpyHF zwYuq?-FBrH)G&@tnx2p{ElHY%d^<_XqVl@nG9F;#nCas!NsiE_BqbzH^-WG|0^I@n zuGW%N4?G{-7Muod1a|e2q=w)IVDe@Qd$LQLnvs&6CP`l+pY%A`lb<@il2jY40~^2( z;mjU<9Snb&S!EC!BV$TZT58JlBmWZP zVPXn}bQ1a0z(Fw8+Z3R5bRpOkdeW3BsZ)HD(sKiqdg*exkCYV}q*Q1PZUDo?aS16C z;Ltw!MZ>;hQWC~K`rY<ZC)QxPVOQoQUiDPa~O z+@{E%5vtU?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&4YuZm@X07D-lRj5-BcXP6U{`z9yNl6y)ro0T@|cZZFi z95PgFCll05S;F6TIYCuT6}8lp14K}ub=Y}Gw_z3Un%Va>3|oUw?Hz#XtXF49Ybn+C ziNtAX=Jq!RR?V`p7+9KDbx1`A>l1*VdOB6~63f(wjM7JZP1R(eXoWB*9wF6Kk}+GT z0|P~MbFOG$O%j~BDq&4f$FEVf=?!`xt}3h))5H?x{4*76W-~PshWu2?pD6}eC$s||>)#>Rp7svfFA8HT z4r}YulVt5O&X{uQ+F+}d0#qrRKc6I(dTNMB3cAq2I3S;&9DIE7oD(m?G#+gZ+b=q( z%IWAylg*Y@?b1ba(`C>T>0%`4TDqt&2B>O7#Uk538<(Q;*VekfWtOnnauw9bFK%k>;FamK;nC3%jQ8X$u~TS^VaYB?{J& z^0Jdo49|M&3tLIbUiBcd23lv(=S&YudFcMHnwBW|r~)X6hUyUY61x~@&Z}HF?ri?U zp&v^0($tTvgLUY==fbO3+butSyF|e{7XL~6M&-Zi(DC(>lp>Wh9B(XRJ_)i;tv5Tl zYU1%R&kfWY8oh`wNy>-P(FqeL3TnkrIin8=+>66wMsj{q+xk zyfC#FmW*lFPhB4=d;+aA{K2!kj~ljJK424JoSJYoP*p~uUe=-iHv7sq?OlHVjuHiZ z$~DXwb8^kH`fItPnvIMoMW>DGS{B~oKX`jbiU$@cg%0RPVRgau2mmpicVsP3LP!te;Dw?1=YB{q_~QIi7VEBGF;l2v1aLsWmvgd z>jQtags<#|YUdctpVogqM9&#EW$%*Z58A}pG-HMPO`58QH({XlzY;tB-+2GnvD+WR z5+`qGjOMR;XNl;R)_*@`&+K}8`J4TIHb`cdM%6k-_@r6#i|f z^lR2%7@bTnD~uIU74GFe0IqFWs`FTM?Bj^66XP}Bc#p=#9u|`;-#%w5#U0&wVyxKG Mc<1x~6r&RU132|!v;Y7A diff --git a/web/package.json b/web/package.json index f07c77dc..53c29a8d 100644 --- a/web/package.json +++ b/web/package.json @@ -14,6 +14,7 @@ "@fontsource/roboto": "^5.0.13", "@mui/icons-material": "^5.16.7", "@mui/material": "^5.15.20", + "devalue": "^5.1.1", "firebase": "^10.12.2", "framer-motion": "^11.3.23", "notistack": "^3.0.1", diff --git a/web/src/api/chat/chat.ts b/web/src/api/chat/chat.ts index 182ee85a..c161e1ba 100644 --- a/web/src/api/chat/chat.ts +++ b/web/src/api/chat/chat.ts @@ -54,7 +54,16 @@ export async function updateMessage( export async function overview(): Promise { const res = await credFetch("GET", endpoints.roomOverview); if (res.status === 401) throw new ErrUnauthorized(); - return await res.json(); + const json: RoomOverview[] = await res.json(); + + if (!Array.isArray(json)) return json; + + for (const room of json) { + if (!room.lastMsg) continue; + room.lastMsg.createdAt = new Date(room.lastMsg.createdAt); + } + + return json; } //// DM関連 //// @@ -74,7 +83,6 @@ export async function sendDM( return res.json(); } -// WARNING: don't use this outside of api/ export async function getDM(friendId: UserID): Promise { const res = await credFetch("GET", endpoints.dmWith(friendId)); if (res.status === 401) throw new ErrUnauthorized(); @@ -82,7 +90,12 @@ export async function getDM(friendId: UserID): Promise { throw new Error( `getDM() failed: expected status code 200, got ${res.status}`, ); - return res.json(); + const json: DMRoom = await res.json(); + if (!Array.isArray(json?.messages)) return json; + for (const m of json.messages) { + m.createdAt = new Date(m.createdAt); + } + return json; } ////グループチャット関連//// diff --git a/web/src/hooks/useSWR.ts b/web/src/hooks/useSWR.ts index 0ce481af..83d3906d 100644 --- a/web/src/hooks/useSWR.ts +++ b/web/src/hooks/useSWR.ts @@ -1,3 +1,4 @@ +import { parse, stringify } from "devalue"; import { useCallback, useEffect, useState } from "react"; import type { ZodSchema } from "zod"; @@ -72,15 +73,16 @@ export function useSWR( const result = schema.safeParse(data); if (!result.success) { console.error( - `WARNING: useSWR: UNEXPECTED ZOD PARSE ERROR: Schema Parse Error: ${result.error.message}`, + `useSWR: Schema Parse Error | in incoming data | at schema ${CACHE_KEY} | Error: ${result.error.message}`, ); + console.log("data:", data); } setState({ data: data, current: "success", error: null, }); - localStorage.setItem(CACHE_KEY, JSON.stringify(data)); + localStorage.setItem(CACHE_KEY, stringify(data)); } catch (e) { setState({ data: null, @@ -92,7 +94,7 @@ export function useSWR( const write = useCallback( (data: T) => { - localStorage.setItem(CACHE_KEY, JSON.stringify(data)); + localStorage.setItem(CACHE_KEY, stringify(data)); }, [CACHE_KEY], ); @@ -115,10 +117,16 @@ function loadOldData( const oldData = localStorage.getItem(CACHE_KEY); if (oldData) { try { - const data = JSON.parse(oldData); - const parse = schema.safeParse(data); - if (!parse.success) - console.error(`useSWR: zodParseError: ${parse.error}`); + const data = parse(oldData); + const parsed = schema.safeParse(data); + if (!parsed.success) { + console.error( + `useSWR: zodParseError | in stale data | at schema ${CACHE_KEY} | ${parsed.error}`, + ); + console.log("data:", data); + // because loading old data isn't critical to the application and wrong stale data may cause several problems, + throw ""; + } return { current: "stale", data,