Skip to content

fix: コードレビュー指摘事項の修正#14

Merged
kwrkb merged 3 commits intomainfrom
fix/review-findings
Feb 25, 2026
Merged

fix: コードレビュー指摘事項の修正#14
kwrkb merged 3 commits intomainfrom
fix/review-findings

Conversation

@kwrkb
Copy link
Copy Markdown
Owner

@kwrkb kwrkb commented Feb 25, 2026

Summary

Test plan

  • npm run lint がエラーなく通ること
  • npm run build が成功すること
  • generating ページでポーリングが正常動作し、ページ離脱時に停止すること
  • 画像生成が after() 経由で正常に完了すること
  • /test ページが本番ビルドで404になること
  • エラー発生時に error.tsx が表示されること

Closes #5, closes #6, closes #8, closes #11, closes #12, closes #13

🤖 Generated with Claude Code

- 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>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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

  • メモリリーク修正: useEffectのcleanup未登録によるメモリリークを修正し、React.use()でparamsを同期解決するように変更しました。
  • バックグラウンド処理の最適化: バックグラウンド画像生成処理をnext/serverafter() APIに移行し、サーバーレス環境での安定性と効率を向上させました。
  • 依存関係の整理: 未使用の@google/generative-ai依存を削除し、package.jsonpackage-lock.jsonをクリーンアップしました。
  • ファイルシステム操作の改善: fs.writeFileSyncおよびfs.existsSyncfs/promisesに置き換え、非同期処理をより適切に扱えるようにしました。
  • 型安全性の強化: any型をunknown型と型ガードに置き換え、コードの型安全性を向上させました。
  • テストページとエラーハンドリングの改善: テストページに本番環境でのガードを追加し、プレースホルダーURLを改善、error.tsxを追加、remotePatternsを削除、fetchTreeDataの重複を解消しました。

🧠 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
  • app/actions/generations.ts
    • next/serverからafter関数をインポートしました。
    • 画像生成の仮URLをローカルのSVGプレースホルダーに変更しました。
    • バックグラウンド画像生成処理をnext/serverafter()APIを使用するように移行し、サーバーレス環境での安定性を向上させました。
  • app/error.tsx
    • アプリケーション全体で予期せぬエラーが発生した場合に表示される新しいエラーページコンポーネントを追加しました。
  • app/gallery/[id]/generating/page.tsx
    • paramsオブジェクトからgenerationIdを同期的に解決するためにReact.use()フックを使用するように変更しました。
    • useEffectフック内のポーリングロジックをリファクタリングし、clearIntervalが確実に呼び出されるように修正しました。
  • app/gallery/[id]/page.tsx
    • getLineage関数内のSupabaseクエリ結果の型アサーションからanyを削除し、明示的なGeneration型を使用するように変更しました。
  • app/test/add-sample/page.tsx
    • プロダクション環境ではこのページがレンダリングされないようにガードを追加しました。
  • app/test/page.tsx
    • プロダクション環境ではnotFound()を呼び出して404エラーを返すようにガードを追加しました。
  • lib/gemini/client.ts
    • ファイルシステム操作に同期的なfsモジュールから非同期的なfs/promisesモジュールへ移行しました。
    • ディレクトリ作成とファイル書き込みにawait fs.mkdirawait fs.writeFileを使用するように変更しました。
    • エラーハンドリングにおいて、any型をunknownに置き換え、より厳密な型ガードを導入しました。
  • lib/queries/tree.ts
    • サーバーサイドとクライアントサイドでツリーデータを取得するロジックの重複を解消するため、共通のfetchTreeData関数を導入しました。
    • SupabaseClientDatabaseの型をインポートし、型安全性を向上させました。
  • next.config.ts
    • images.remotePatterns設定を削除しました。
  • package-lock.json
    • 未使用の@google/generative-aiパッケージの依存関係を削除しました。
    • 複数のパッケージからpeerプロパティを削除しました。
  • package.json
    • 未使用の@google/generative-aiパッケージの依存関係を削除しました。
  • public/images/placeholder.svg
    • 画像生成中のプレースホルダーとして使用される新しいSVGファイルを追加しました。
Activity
  • このプルリクエストには、現在報告するアクティビティはありません。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、以前のコードレビューでの指摘事項を修正するもので、多岐にわたる改善が含まれています。特に、next/serverafter() API を利用したバックグラウンド処理への移行、fs/promises の採用による非同期 I/O の徹底、any 型から unknown 型への移行による型安全性の向上など、堅牢性と保守性を高めるための重要な変更が多数行われています。全体として、コード品質を向上させる素晴らしい修正です。

いくつか改善の余地がある点についてコメントしました。特に、generating ページでのポーリング処理に関するクリティカルなバグが1点見つかりましたので、ご確認をお願いします。

Comment on lines +37 to +64
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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

checkStatus 関数内で pollInterval を使用していますが、pollIntervalcheckStatus の定義より後で const を使って宣言されています。const で宣言された変数は宣言前にアクセスできないため、checkStatus が実行されると ReferenceError: Cannot access 'pollInterval' before initialization が発生します。

pollIntervallet で先に宣言し、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);

Comment thread app/actions/generations.ts Outdated
Comment on lines 80 to 86
after(async () => {
try {
await generateImageInBackground(data.id, prompt.trim());
} catch (error) {
console.error('Background image generation failed:', error);
}
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

generateImageInBackground 関数は内部でエラーを捕捉し、DBのステータスを failed に更新する処理を行っています。そのため、この関数は例外をスローしません。したがって、ここでの try...catch ブロックは冗長であり、catch 節は到達不能コードになっています。

after には generateImageInBackground を直接渡すことで、コードをシンプルにできます。

    after(() => {
      generateImageInBackground(data.id, prompt.trim());
    });

Comment thread app/error.tsx
Comment on lines +6 to +11
export default function ErrorPage({
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

エラーページが表示された際に、発生したエラーを開発者が追跡できるように、エラー内容をコンソールや外部の監視サービスに出力することが推奨されます。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]);

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread next.config.ts
Comment on lines 3 to 5
const nextConfig: NextConfig = {
/* config options here */
images: {
remotePatterns: [
{
protocol: "https",
hostname: "**",
},
],
},
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

kwrkb and others added 2 commits February 26, 2026 07:18
- 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>
@kwrkb kwrkb merged commit 92c95b7 into main Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant