Sfoglia il codice sorgente

update serena memories

Yuki Takei 7 mesi fa
parent
commit
a35b711864

BIN
.serena/cache/typescript/document_symbols_cache_v23-06-25.pkl


+ 35 - 121
.serena/memories/apps-app-technical-specs.md

@@ -1,121 +1,35 @@
-# apps/app 技術仕様・開発ガイド
-
-## ファイル命名規則
-- Next.js ページ: `*.page.tsx`
-- React コンポーネント: `ComponentName.tsx`
-- スタイル: `ComponentName.module.scss`
-- テスト: `*.spec.ts`, `*.test.ts`, `*.integ.ts`
-- 型定義: `*.d.ts`
-
-## 重要な設定ファイル
-- `next.config.js` - Next.js 設定
-- `tsconfig.json` - TypeScript 設定(複数レイヤー)
-- `package.json` - 依存関係とスクリプト
-- `turbo.json` - Turborepo 設定
-
-## API 構造
-### API v3 (`server/routes/apiv3/`)
-- RESTful API エンドポイント
-- Express.js ルーター使用
-- バリデーション・認証ミドルウェア
-- OpenAPI 仕様準拠
-
-### フィーチャー API
-各フィーチャーが独自の API ルートを持つ場合あり
-例: `features/openai/server/routes/`
-
-## 状態管理パターン
-### Jotai (推奨・新)
-- `states/` ディレクトリ
-- アトミックな状態管理
-- ファイル別に関心事を分離
-
-### SWR (データフェッチング)
-- サーバーサイドデータの管理
-- キャッシュとリバリデーション
-- `stores-universal/context.tsx` でコンテキスト提供
-
-## スタイリング指針
-### SCSS 構造
-- `styles/` ディレクトリに全体スタイル
-- コンポーネント別に `.module.scss`
-- Atomic Design っぽい構造(atoms, molecules, organisms)
-
-### CSS Modules
-- スコープ化されたクラス名
-- TypeScript での型安全性
-
-## データベース・モデル
-### Mongoose モデル (`server/models/`)
-- MongoDB スキーマ定義
-- バリデーション・ミドルウェア
-- インデックス定義
-
-### シリアライザー
-- `serializers/` でレスポンス形式を統一
-- クライアント向けデータ変換
-
-## セキュリティ機能
-### 認証・認可
-- 複数の認証プロバイダー対応
-- ページ・API レベルでの権限制御
-- アクセストークン・API キー
-
-### XSS・CSRF 対策
-- `services/general-xss-filter/`
-- サニタイゼーション機能
-
-## 国際化 (i18n)
-- next-i18next 使用
-- 多言語リソース管理
-- サーバーサイド・クライアントサイド両対応
-
-## テスト戦略
-### テストタイプ
-- `.spec.ts` - ユニットテスト
-- `.integ.ts` - 統合テスト
-- Playwright - E2E テスト
-
-### テスト実行
-- Jest (ユニット・統合)
-- Vitest (一部)
-- GitHub Actions CI
-
-## プラグインシステム
-### GROWI プラグイン
-- `features/growi-plugin/`
-- 動的プラグイン読み込み
-- テーマ・テンプレート拡張
-
-## パフォーマンス最適化
-### レンダリング
-- サーバーサイドレンダリング (SSR)
-- 静的生成 (SSG) 一部対応
-- コード分割
-
-### 検索機能
-- Elasticsearch 統合
-- 全文検索インデックス
-- 検索結果キャッシュ
-
-## 監視・ロギング
-### OpenTelemetry
-- `features/opentelemetry/`
-- メトリクス・トレース収集
-- カスタムメトリクス
-
-### ログ
-- Bunyan ロガー使用
-- 構造化ログ出力
-
-## 開発時の注意点
-1. 新機能は features/ に実装
-2. TypeScript strict モード準拠
-3. ESLint ルール遵守
-4. コンポーネントは関数型で実装
-5. 状態管理は Jotai 優先
-6. API は v3 形式で実装
-7. セキュリティチェック必須
-8. 国際化対応
-9. テストカバレッジ維持
-10. パフォーマンス影響考慮
+# apps/app 技術仕様
+
+## ファイル構造・命名
+- Next.js: `*.page.tsx`
+- テスト: `*.spec.ts`, `*.integ.ts`
+- コンポーネント: `ComponentName.tsx`
+
+## API構造
+- **API v3**: `server/routes/apiv3/` (RESTful + OpenAPI準拠)
+- **Features API**: `features/*/server/routes/`
+
+## 状態管理
+- **Jotai** (推奨): `states/` - アトミック分離
+- **SWR**: データフェッチ・キャッシュ - `stores-universal/context.tsx`
+
+## データベース
+- **Mongoose**: `server/models/` (スキーマ定義)
+- **Serializers**: `serializers/` (レスポンス変換)
+
+## セキュリティ・i18n
+- **認証**: 複数プロバイダー + アクセストークン
+- **XSS対策**: `services/general-xss-filter/`
+- **i18n**: next-i18next (サーバー・クライアント両対応)
+
+## システム機能
+- **検索**: Elasticsearch統合
+- **監視**: OpenTelemetry (`features/opentelemetry/`)
+- **プラグイン**: 動的読み込み (`features/growi-plugin/`)
+
+## 開発ガイドライン
+1. 新機能は `features/` 実装
+2. TypeScript strict準拠
+3. Jotai状態管理優先
+4. API v3形式
+5. セキュリティ・i18n・テスト必須

+ 37 - 0
.serena/memories/browser-back-navigation-bug-fix.md

@@ -0,0 +1,37 @@
+# ブラウザバックナビゲーションバグ修正
+
+## 問題の概要
+ページA → ページB → ページC → ページD と遷移してブラウザバックすると、ページBやページCの内容がレンダリングされないことがある。URLバーは更新されているが、ページコンテンツが表示されない現象。
+
+## 根本原因
+1. **競合状態(Race Condition)**: 高速なブラウザバック時に `fetchCurrentPage` が複数回並行実行され、古いリクエストが新しいリクエストの結果を上書き
+2. **状態更新の不整合**: pageIdとpageDataの更新タイミングのズレ
+3. **navigationState.shouldFetchの判定ミス**: 複雑な条件分岐で期待される場面でfetchがスキップ
+
+## 実装した修正
+
+### 1. useSameRouteNavigation.ts の改善
+- **競合防止**: `currentFetchRef` を使用して現在のfetch操作を追跡
+- **重複実行防止**: `lastPathnameRef` で前回のpathnameと比較
+- **fetch結果の検証**: 完了したfetch操作が最新のものかチェック
+- **エラーハンドリング**: 古いfetch操作のエラーは無視
+
+### 2. navigation-utils.ts の改善  
+- **`createNavigationState`関数の強化**: `hasNoCurrentData` チェックを追加
+- **より確実な判定ロジック**: ブラウザバック時のエッジケースに対応
+
+## テスト方法
+1. ページA → ページB → ページC → ページD と順番に遷移
+2. 高速にブラウザバックを実行(連続クリック)
+3. 各ページで正しいコンテンツが表示されることを確認
+4. 開発者ツールのConsoleでdebugging logを確認
+
+## 期待される結果
+- ブラウザバック時に常に正しいページコンテンツが表示される
+- URLバーとページ内容が一致する
+- 競合状態によるデータの不整合が解消される
+
+## 注意点
+- `fetchCurrentPage`の重複実行は防止できるが、完全なキャンセルは不可
+- console.debugでfetch操作の追跡ログが出力される(本番では削除推奨)
+- 複雑な判定ロジックのため、今後の機能追加時は慎重にテスト

+ 0 - 45
.serena/memories/development_environment.md

@@ -1,45 +0,0 @@
-# 開発環境とツール
-
-## 推奨システム要件
-- **Node.js**: ^20 || ^22
-- **パッケージマネージャー**: pnpm 10.4.1
-- **OS**: Linux(Ubuntuベース)、macOS、Windows
-
-## 利用可能なLinuxコマンド
-基本的なLinuxコマンドが利用可能:
-- `apt`, `dpkg`: パッケージ管理
-- `git`: バージョン管理
-- `curl`, `wget`: HTTP クライアント
-- `ssh`, `scp`, `rsync`: ネットワーク関連
-- `ps`, `lsof`, `netstat`, `top`: プロセス・ネットワーク監視
-- `tree`, `find`, `grep`: ファイル検索・操作
-- `zip`, `unzip`, `tar`, `gzip`, `bzip2`, `xz`: アーカイブ操作
-
-## 開発用ブラウザ
-```bash
-# ローカルサーバーをブラウザで開く
-"$BROWSER" http://localhost:3000
-```
-
-## 環境変数管理
-- **dotenv-flow**: 環境ごとの設定管理
-- 環境ファイル:
-  - `.env.development`: 開発環境
-  - `.env.production`: 本番環境
-  - `.env.test`: テスト環境
-  - `.env.*.local`: ローカル固有設定
-
-## デバッグ
-```bash
-# デバッグモードでサーバー起動
-cd apps/app && pnpm run dev  # --inspectフラグ付きでnodemon起動
-
-# REPL(Read-Eval-Print Loop)
-cd apps/app && pnpm run repl
-```
-
-## VS Code設定
-`.vscode/` ディレクトリに設定ファイルが含まれており、推奨拡張機能や設定が適用される。
-
-## Docker対応
-各アプリケーションにDockerファイルが含まれており、コンテナベースでの開発も可能。

+ 108 - 0
.serena/memories/navigation-bug-fix-refactoring-plan.md

@@ -0,0 +1,108 @@
+# Navigation Bug Fix Refactoring Plan
+
+## Background
+Successfully fixed the browser back/forward navigation bug where page content wasn't updating correctly. The fix involved:
+- Adding `useRouter` to monitor `router.asPath` 
+- Using `router.asPath || props.currentPathname` for correct path detection
+- Adding `router.asPath` to useEffect dependencies
+
+## Current State Analysis
+
+### Problems to Address
+1. **Debug logs scattered throughout the code** - Need to remove console.debug/console.error statements
+2. **Logic concentration in use-same-route-navigation.ts** - Single large useEffect with complex logic
+3. **navigation-utils.ts redundancy** - Only contains `extractPageIdFromPathname` function
+4. **Code readability** - Complex conditional logic and state management in one place
+
+### Core Functionality to Preserve
+- Browser back/forward navigation support via `router.asPath` monitoring
+- Race condition prevention with `isFetchingRef` and `lastProcessedPathnameRef`
+- Initial data skip logic for SSR optimization
+- Proper state clearing and updating sequence
+- Error handling during fetch operations
+
+## Refactoring Plan
+
+### Phase 1: Test Coverage
+**Objective**: Create comprehensive tests to prevent regressions
+
+#### Test Scenarios
+1. **Normal Navigation Flow**
+   - A→B→C→D transitions trigger correct fetches
+   - Page data updates correctly
+   - No duplicate fetches for same path
+
+2. **Browser Back/Forward Navigation**
+   - Browser back from D→C displays correct content
+   - Browser forward navigation works correctly
+   - URL and content stay synchronized
+
+3. **Edge Cases**
+   - Initial load with SSR data (skipSSR scenarios)
+   - Concurrent navigation attempts
+   - Network errors during fetch
+   - Empty/null page data handling
+
+4. **State Management**
+   - pageId updates correctly
+   - currentPage state synchronization
+   - editing markdown updates
+
+#### Test Implementation Strategy
+- Use Jest + React Testing Library
+- Mock `useRouter`, `useFetchCurrentPage`, page state hooks
+- Create helper functions for navigation simulation
+- Focus on behavior assertions rather than implementation details
+
+### Phase 2: Code Refactoring
+
+#### Option A: Keep Separation (Recommended)
+**navigation-utils.ts** - Pure utility functions
+```typescript
+// Path processing utilities
+export const extractPageIdFromPathname = (pathname: string): string | null
+export const shouldFetchPage = (params: ShouldFetchParams): boolean
+export const createNavigationTarget = (router: NextRouter, props: Props): string
+```
+
+**use-same-route-navigation.ts** - Hook with extracted functions
+```typescript
+// Private helper functions
+const useNavigationRefs = () => ({ lastProcessedRef, isFetchingRef })
+const useNavigationTarget = (router, props) => string
+const usePageDataUpdater = () => (targetPathname: string) => Promise<void>
+
+// Main hook with clean useEffect
+export const useSameRouteNavigation = (props, ...) => void
+```
+
+#### Option B: Consolidation
+Merge navigation-utils.ts into use-same-route-navigation.ts if utilities are only used there.
+
+#### Refactoring Steps
+1. **Extract pure functions** from useEffect logic
+2. **Create custom sub-hooks** for related functionality
+3. **Remove debug logging** throughout codebase
+4. **Simplify conditional logic** with extracted functions
+5. **Improve error handling** with consistent patterns
+6. **Add comprehensive JSDoc** documentation
+
+### Phase 3: Validation
+1. **Run comprehensive test suite** - All tests must pass
+2. **Manual testing** of navigation scenarios
+3. **Performance verification** - No regressions in render frequency
+4. **Code review** - Ensure readability improvements
+
+## Success Criteria
+- [ ] All tests pass (100% coverage of critical paths)
+- [ ] No debug logs in production code
+- [ ] Functions are single-responsibility and testable
+- [ ] Code is self-documenting with clear naming
+- [ ] Browser navigation bug remains fixed
+- [ ] No performance regressions
+
+## Implementation Notes
+- Preserve the core fix: `router.asPath` monitoring
+- Maintain backward compatibility with existing API
+- Keep useEffect dependencies minimal and clear
+- Ensure error boundaries don't break navigation flow

+ 0 - 94
.serena/memories/suggested_commands.md

@@ -1,94 +0,0 @@
-# 推奨開発コマンド集
-
-## セットアップ
-```bash
-# 初期セットアップ
-pnpm run bootstrap
-# または
-pnpm install
-```
-
-## 開発サーバー
-```bash
-# メインアプリケーション開発モード
-cd apps/app && pnpm run dev
-
-# ルートから起動(本番用ビルド後)
-pnpm start
-```
-
-## ビルド
-```bash
-# メインアプリケーションのビルド
-pnpm run app:build
-
-# Slackbot Proxyのビルド
-pnpm run slackbot-proxy:build
-
-# 全体ビルド(Turboで並列実行)
-turbo run build
-```
-
-## Lint・フォーマット
-```bash
-# 【推奨】Biome実行(lint + format)
-pnpm run lint:biome
-
-# 【過渡期】ESLint実行(廃止予定)
-pnpm run lint:eslint
-
-# Stylelint実行
-pnpm run lint:styles
-
-# 全てのLint実行(過渡期対応)
-pnpm run lint
-
-# TypeScript型チェック
-pnpm run lint:typecheck
-```
-
-## テスト
-```bash
-# 【推奨】Vitestテスト実行
-pnpm run test:vitest
-
-# 【過渡期】Jest(統合テスト)(廃止予定)
-pnpm run test:jest
-
-# 全てのテスト実行(過渡期対応)
-pnpm run test
-
-# Vitestをカバレッジ付きで実行
-vitest run --coverage
-
-# E2Eテスト(Playwright)
-npx playwright test
-```
-
-## データベース関連
-```bash
-# マイグレーション実行
-cd apps/app && pnpm run migrate
-
-# 開発環境でのマイグレーション
-cd apps/app && pnpm run dev:migrate
-
-# マイグレーション状態確認
-cd apps/app && pnpm run dev:migrate:status
-```
-
-## その他の便利コマンド
-```bash
-# REPL起動
-cd apps/app && pnpm run repl
-
-# OpenAPI仕様生成
-cd apps/app && pnpm run openapi:generate-spec:apiv3
-
-# クリーンアップ
-cd apps/app && pnpm run clean
-```
-
-## 注意事項
-- ESLintとJestは廃止予定のため、新規開発ではBiomeとVitestを使用してください
-- 既存のコードは段階的に移行中です

+ 41 - 42
.serena/memories/tech_stack.md

@@ -1,42 +1,41 @@
-# 技術スタック
-
-## プログラミング言語
-- **TypeScript**: メイン言語(~5.0.0)
-- **JavaScript**: 一部のコンポーネント
-
-## フロントエンド
-- **Next.js**: Reactベースのフレームワーク
-- **React**: UIライブラリ
-- **Vite**: ビルドツール、開発サーバー
-- **SCSS**: スタイルシート
-- **SWR**: グローバルステート管理、データフェッチ・キャッシュ管理(^2.3.2)
-
-## バックエンド
-- **Node.js**: ランタイム(^20 || ^22)
-- **Express.js**: Webフレームワーク(推測)
-- **MongoDB**: データベース
-- **Mongoose**: MongoDB用ORM(^6.13.6)
-  - mongoose-gridfs: GridFS対応(^1.2.42)
-  - mongoose-paginate-v2: ページネーション(^1.3.9)
-  - mongoose-unique-validator: バリデーション(^2.0.3)
-
-## 開発ツール
-- **pnpm**: パッケージマネージャー(10.4.1)
-- **Turbo**: モノレポビルドシステム(^2.1.3)
-- **ESLint**: Linter(weseek設定を使用)【廃止予定 - 現在は過渡期】
-- **Biome**: 統一予定のLinter/Formatter
-- **Stylelint**: CSS/SCSSのLinter
-- **Jest**: テスティングフレームワーク【廃止予定 - 現在は過渡期】
-- **Vitest**: 高速テスティングフレームワーク【統一予定】
-- **Playwright**: E2Eテスト【統一予定】
-
-## その他のツール
-- **SWC**: TypeScriptコンパイラー(高速)
-- **ts-node**: TypeScript直接実行
-- **nodemon**: 開発時のホットリロード
-- **dotenv-flow**: 環境変数管理
-- **Swagger/OpenAPI**: API仕様
-
-## 移行計画
-- **Linter**: ESLint → Biome に統一予定
-- **テスト**: Jest → Vitest + Playwright に統一予定
+# 技術スタック & 開発環境
+
+## コア技術
+- **TypeScript** ~5.0.0 + **Next.js** (React)
+- **Node.js** ^20||^22 + **MongoDB** + **Mongoose** ^6.13.6
+- **pnpm** 10.4.1 + **Turbo** ^2.1.3 (モノレポ)
+
+## 状態管理・データ
+- **Jotai**: アトミック状態管理(推奨)
+- **SWR** ^2.3.2: データフェッチ・キャッシュ
+
+## 開発ツール移行状況
+| 従来 | 移行先 | 状況 |
+|------|--------|------|
+| ESLint | **Biome** | 新規推奨 |
+| Jest | **Vitest** + **Playwright** | 新規推奨 |
+
+## 主要コマンド
+```bash
+# 開発
+cd apps/app && pnpm run dev
+
+# 品質チェック
+pnpm run lint:biome        # 新規推奨
+pnpm run lint:typecheck    # 型チェック正式コマンド
+pnpm run test:vitest       # 新規推奨
+
+# ビルド
+pnpm run app:build
+turbo run build           # 並列ビルド
+```
+
+## ファイル命名規則
+- Next.js: `*.page.tsx`
+- テスト: `*.spec.ts` (Vitest), `*.integ.ts`
+- コンポーネント: `ComponentName.tsx`
+
+## API・アーキテクチャ
+- **API v3**: `server/routes/apiv3/` (RESTful + OpenAPI)
+- **Features**: `features/*/` (機能別分離)
+- **SCSS**: CSS Modules使用

+ 70 - 0
.serena/memories/vitest-testing-tips-and-best-practices.md

@@ -0,0 +1,70 @@
+# Vitest + TypeScript Testing Guide
+
+## 核心技術要素
+
+### tsconfig.json最適設定
+```json
+{
+  "compilerOptions": {
+    "types": ["vitest/globals"]  // グローバルAPI: describe, it, expect等をインポート不要化
+  }
+}
+```
+
+### vitest-mock-extended: 型安全モッキング
+```typescript
+import { mockDeep, type DeepMockProxy } from 'vitest-mock-extended';
+
+// 完全型安全なNext.js Routerモック
+const mockRouter: DeepMockProxy<NextRouter> = mockDeep<NextRouter>();
+mockRouter.asPath = '/test-path';  // TypeScript補完・型チェック有効
+
+// 複雑なUnion型も完全サポート
+interface ComplexProps {
+  currentPageId?: string | null;
+  currentPathname?: string | null;
+}
+const mockProps: DeepMockProxy<ComplexProps> = mockDeep<ComplexProps>();
+```
+
+### React Testing Library + Jotai統合
+```typescript
+const renderWithProvider = (ui: React.ReactElement, scope?: Scope) => {
+  const Wrapper = ({ children }: { children: React.ReactNode }) => (
+    <Provider scope={scope}>{children}</Provider>
+  );
+  return render(ui, { wrapper: Wrapper });
+};
+```
+
+## 実践パターン
+
+### 非同期テスト
+```typescript
+import { waitFor, act } from '@testing-library/react';
+
+await act(async () => {
+  result.current.triggerAsyncAction();
+});
+
+await waitFor(() => {
+  expect(result.current.isLoading).toBe(false);
+});
+```
+
+### 詳細アサーション
+```typescript
+expect(mockFunction).toHaveBeenCalledWith(
+  expect.objectContaining({
+    pathname: '/expected-path',
+    data: expect.any(Object)
+  })
+);
+```
+
+## Jest→Vitest移行要点
+- `jest.config.js` → `vitest.config.ts`
+- `@types/jest` → `vitest/globals`
+- ESModulesネイティブサポート → 高速起動・実行
+
+この設定により型安全性と保守性を両立した高品質テストが可能。