Skip to content

fix:useEffect内でuseStateを使った関数を使っていた問題の修正 #60#62

Open
ponmalnya wants to merge 2 commits intomasterfrom
fixUseState#60
Open

fix:useEffect内でuseStateを使った関数を使っていた問題の修正 #60#62
ponmalnya wants to merge 2 commits intomasterfrom
fixUseState#60

Conversation

@ponmalnya
Copy link
Copy Markdown
Collaborator

app/history/page.tsx のseEffect内でUsestateを同期呼び出ししていたため、余計なレンダリングが発生してしまう問題の修正。

修正内容

app/history/page.tsx
useEffect冒頭の不要な初期化ようのuseStateの削除

app/page.tsx
UserIdをDBで管理することを見越してuseEffect内の処理を非同期の関数に閉じ込めました

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aima Ready Ready Preview, Comment Mar 12, 2026 5:22am

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

useEffect 内の処理を整理して不要な再レンダリングや型の不整合を避け、今後の非同期化(例: UserId をDB管理)にも対応しやすくするためのPRです。

Changes:

  • app/recipes/page.tsxweather クエリのパースを型安全にし、レシピ取得を async 関数に切り出し(依存配列も weather を追加)
  • app/page.tsx で認証チェック処理を async 関数に閉じ込め、cleanup 用フラグを追加
  • app/history/page.tsxuseEffect 冒頭の初期化(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;
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUserId は現状 number | null を返す同期関数(lib/userStore.ts)なので、ここで async + await にすると不要にマイクロタスク境界が入ります。その結果、cleanup 後でも router.replace が走り得て cancelled フラグの意図(アンマウント後の副作用抑止)とズレるので、同期呼び出しに戻すか、少なくとも router.replacecancelled を見て抑止するようにしてください。

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ponmalnya ponmalnya marked this pull request as ready for review March 12, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants