Skip to content

Fix useProject hook state isolation bug and AI chat space race condition#131

Merged
Stasshe merged 4 commits intomainfrom
copilot/investigate-project-ts-issues
Dec 3, 2025
Merged

Fix useProject hook state isolation bug and AI chat space race condition#131
Stasshe merged 4 commits intomainfrom
copilot/investigate-project-ts-issues

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

  • Investigate why project.ts (useProject hook) causes issues when used from different components
    • Each useProject() call creates independent state, causing currentProject to be null and file saves to silently fail
  • Create projectStore (Zustand) for global project state management
  • Fix EditorTabType, DiffTabType, PreviewTabType to use projectStore instead of useProject
  • Sync projectStore from page.tsx when project changes
  • Remove unused useProject import from OperationWindow
  • Fix AI chat space creation race condition (user message and AI response creating separate spaces)
  • Apply code review feedback: use getCurrentProjectId() utility consistently
  • Add PROJECT-ID-BEST-PRACTICES.md documentation guide
  • Run code review and security checks
Original prompt

PR130での変更のように、project.ts経由で使用するとなぜダメなのかを調査し、もし他のところで今のところ使ってないなら、(現在は既存のバグはなかった)ややこしいし消してみてもいいかも?あと、aiのチャットスペースがなかった時、ユーザーの送信でスペースの作成が1回、レスポンスで1回と、別々になってしまう。


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ect access

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate issues with project.ts usage Fix useProject hook state isolation bug and AI chat space race condition Dec 3, 2025
Copilot AI requested a review from Stasshe December 3, 2025 05:20
@Stasshe
Copy link
Owner

Stasshe commented Dec 3, 2025

@copilot まだ他のファイルで、= useProject()みたいなのを使ってた気がするんだけど、気のせい?src/で検索してくれん?あと、extension側にはどうやってprojectid渡されてるか調査して。

Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot まだ他のファイルで、= useProject()みたいなのを使ってた気がするんだけど、気のせい?src/で検索してくれん?あと、extension側にはどうやってp...

調査結果:

useProject()の使用状況

  • src/app/page.tsx - 唯一の権威ソースとして使用(OK)
  • src/engine/core/project.ts - 定義
  • その他のファイルではコメントとして残っているのみ(実際の呼び出しなし)

= useProject()パターンの検索結果は0件でした。

extension側へのprojectId渡し方
extension側はcontext.projectId経由でプロジェクトIDを受け取ります:

  1. page.tsxuseProject()からcurrentProjectを取得
  2. BottomPanel/RightSidebarにprops経由でcurrentProjectId={currentProject?.id}を渡す
  3. Terminalからextensionコマンド実行時にcontext.projectIdとして渡す

この仕組みはpropsベースなので、useProjectのバグの影響を受けません。

@Stasshe
Copy link
Owner

Stasshe commented Dec 3, 2025

@copilot projectIDに関しての、ベストプラクティスのガイドをmdドキュメント追加して。

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
@Stasshe Stasshe temporarily deployed to copilot/investigate-project-ts-issues - pyxis-code PR #131 December 3, 2025 05:34 — with Render Destroyed
Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot projectIDに関しての、ベストプラクティスのガイドをmdドキュメント追加して。

Development/PROJECT-ID-BEST-PRACTICES.md を追加しました (f87a39d)。

内容:

  • useProject()フックの問題と背景
  • アーキテクチャ図(mermaid)
  • 4つの使用パターン(Reactコンポーネント内、コールバック内、props経由、Extension内)
  • 非推奨パターン
  • APIリファレンス
  • ファイル操作時のコード例
  • チェックリスト

@Stasshe Stasshe marked this pull request as ready for review December 3, 2025 05:39
@Stasshe Stasshe merged commit d8ca7ee into main Dec 3, 2025
@Stasshe Stasshe deleted the copilot/investigate-project-ts-issues branch December 3, 2025 10:06
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