fix:useEffect内でuseStateを使った関数を使っていた問題の修正 #60#62
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
useEffect 内の処理を整理して不要な再レンダリングや型の不整合を避け、今後の非同期化(例: UserId をDB管理)にも対応しやすくするためのPRです。
Changes:
app/recipes/page.tsxでweatherクエリのパースを型安全にし、レシピ取得をasync関数に切り出し(依存配列もweatherを追加)app/page.tsxで認証チェック処理をasync関数に閉じ込め、cleanup 用フラグを追加app/history/page.tsxでuseEffect冒頭の初期化(setLoading(true),setError(null))を削除
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| aima-front/app/recipes/page.tsx | weather のパース関数追加と、レシピ取得処理の async 化・依存配列の是正 |
| aima-front/app/page.tsx | ユーザーID取得フローを async 関数へ移し、cleanup フラグを導入 |
| aima-front/app/history/page.tsx | useEffect 冒頭の状態初期化を削除(ただし空白行が混入) |
Comment on lines
+15
to
+20
| const checkAuth = async () => { | ||
| const id = await getUserId(); | ||
| if (!id) { | ||
| router.replace("/onboarding"); | ||
| return; | ||
| } |
There was a problem hiding this comment.
getUserId は現状 number | null を返す同期関数(lib/userStore.ts)なので、ここで async + await にすると不要にマイクロタスク境界が入ります。その結果、cleanup 後でも router.replace が走り得て cancelled フラグの意図(アンマウント後の副作用抑止)とズレるので、同期呼び出しに戻すか、少なくとも router.replace も cancelled を見て抑止するようにしてください。
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
app/history/page.tsxのseEffect内でUsestateを同期呼び出ししていたため、余計なレンダリングが発生してしまう問題の修正。修正内容
app/history/page.tsxuseEffect冒頭の不要な初期化ようのuseStateの削除
app/page.tsxUserIdをDBで管理することを見越してuseEffect内の処理を非同期の関数に閉じ込めました