Conversation
- useEffectのcleanup未登録によるメモリリークを修正 (React.use()で解決) - バックグラウンド画像生成をNext.js after() APIに移行 - 不要な@google/generative-ai依存を削除 - 同期ファイルI/Oをfs/promisesに置き換え - any型をunknown + 型ガードに置き換え - テストページの本番環境ガード追加 - プレースホルダーURLをローカルSVGに変更 - remotePatterns全ホスト許可を削除 - error.tsx追加 - fetchTreeDataの重複ロジックを共通関数に抽出 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @kwrkb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! このプルリクエストは、コードレビューで指摘された複数の改善点を修正し、アプリケーションの安定性、パフォーマンス、保守性を向上させることを目的としています。特に、メモリリークの解消、サーバーレス環境でのバックグラウンド処理の最適化、型安全性の強化、および開発用ページのプロダクション環境からの分離に焦点を当てています。これにより、より堅牢で効率的なアプリケーション運用が期待されます。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
このプルリクエストは、以前のコードレビューでの指摘事項を修正するもので、多岐にわたる改善が含まれています。特に、next/server の after() API を利用したバックグラウンド処理への移行、fs/promises の採用による非同期 I/O の徹底、any 型から unknown 型への移行による型安全性の向上など、堅牢性と保守性を高めるための重要な変更が多数行われています。全体として、コード品質を向上させる素晴らしい修正です。
いくつか改善の余地がある点についてコメントしました。特に、generating ページでのポーリング処理に関するクリティカルなバグが1点見つかりましたので、ご確認をお願いします。
| const supabase = createClient(); | ||
|
|
||
| const checkStatus = async () => { | ||
| const { data, error } = await supabase | ||
| .from("generations") | ||
| .select("status") | ||
| .eq("id", generationId) | ||
| .single(); | ||
|
|
||
| if (error) { | ||
| console.error("Status check error:", error); | ||
| return; | ||
| } | ||
|
|
||
| if (data.status === "completed") { | ||
| setStatus("completed"); | ||
| clearInterval(pollInterval); | ||
| setTimeout(() => { | ||
| router.push(`/gallery/${generationId}/result`); | ||
| }, 1500); | ||
| } else if (data.status === "failed") { | ||
| setStatus("failed"); | ||
| clearInterval(pollInterval); | ||
| } | ||
| }; | ||
|
|
||
| checkStatus(); | ||
| const pollInterval = setInterval(checkStatus, 2000); |
There was a problem hiding this comment.
checkStatus 関数内で pollInterval を使用していますが、pollInterval は checkStatus の定義より後で const を使って宣言されています。const で宣言された変数は宣言前にアクセスできないため、checkStatus が実行されると ReferenceError: Cannot access 'pollInterval' before initialization が発生します。
pollInterval を let で先に宣言し、setInterval の結果を代入するように修正する必要があります。
const supabase = createClient();
let pollInterval: ReturnType<typeof setInterval>;
const checkStatus = async () => {
const { data, error } = await supabase
.from("generations")
.select("status")
.eq("id", generationId)
.single();
if (error) {
console.error("Status check error:", error);
return;
}
if (data.status === "completed") {
setStatus("completed");
clearInterval(pollInterval);
setTimeout(() => {
router.push(`/gallery/${generationId}/result`);
}, 1500);
} else if (data.status === "failed") {
setStatus("failed");
clearInterval(pollInterval);
}
};
checkStatus();
pollInterval = setInterval(checkStatus, 2000);
| after(async () => { | ||
| try { | ||
| await generateImageInBackground(data.id, prompt.trim()); | ||
| } catch (error) { | ||
| console.error('Background image generation failed:', error); | ||
| } | ||
| }); |
There was a problem hiding this comment.
| export default function ErrorPage({ | ||
| reset, | ||
| }: { | ||
| error: Error & { digest?: string }; | ||
| reset: () => void; | ||
| }) { |
There was a problem hiding this comment.
エラーページが表示された際に、発生したエラーを開発者が追跡できるように、エラー内容をコンソールや外部の監視サービスに出力することが推奨されます。error prop が渡されていますが、現在使用されていません。
useEffect を使ってエラーをログ出力する処理を追加しましょう。これには、react から useEffect をインポートし、props から error を受け取るように変更する必要があります。
export default function ErrorPage({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
// Sentryなどのエラー監視サービスに送信することも検討してください
console.error(error);
}, [error]);
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef81645b0e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const nextConfig: NextConfig = { | ||
| /* config options here */ | ||
| images: { | ||
| remotePatterns: [ | ||
| { | ||
| protocol: "https", | ||
| hostname: "**", | ||
| }, | ||
| ], | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Restore remotePatterns for legacy image URLs
Removing images.remotePatterns causes next/image to reject any generation.image_url stored as an absolute URL, and this codebase still renders DB values directly (for example in app/gallery/[id]/page.tsx). Rows created before this change can still contain external URLs (such as the previous placeholder), so after deploying this commit those records will fail at runtime with an invalid src error; keep an allowlist for legacy hosts or migrate existing rows before dropping the config.
Useful? React with 👍 / 👎.
- pollInterval のTDZ問題を修正(const宣言を checkStatus() の前に移動) - after() 内の冗長な try/catch を除去 - error.tsx で error prop をコンソール出力するように修正 - remotePatterns を既存DB互換のため via.placeholder.com に限定して復元 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
React.use()で params を同期解決)next/serverのafter()APIに移行 (サーバーレス対応)@google/generative-ai依存を削除fs.writeFileSync/fs.existsSyncをfs/promisesに置き換えany型をunknown+ 型ガードに置き換えTest plan
npm run lintがエラーなく通ることnpm run buildが成功することafter()経由で正常に完了すること/testページが本番ビルドで404になることCloses #5, closes #6, closes #8, closes #11, closes #12, closes #13
🤖 Generated with Claude Code