From b52a605510314bd89aae7ba45a18107baaf61a9c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 06:28:27 +0000 Subject: [PATCH 1/4] Initial plan From 160a2cb6f3c8a3f8eb82e56f301b896ef7fcfed4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 06:38:24 +0000 Subject: [PATCH 2/4] docs: add comprehensive AI-friendly documentation Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com> --- .cursorrules | 251 ++++++++++++++++++++++++++++++ .github/copilot/instructions.md | 180 ++++++++++++++++++++++ AI_DEVELOPMENT_GUIDE.md | 265 ++++++++++++++++++++++++++++++++ README.md | 17 ++ 4 files changed, 713 insertions(+) create mode 100644 .cursorrules create mode 100644 .github/copilot/instructions.md create mode 100644 AI_DEVELOPMENT_GUIDE.md diff --git a/.cursorrules b/.cursorrules new file mode 100644 index 000000000..9be46d3b0 --- /dev/null +++ b/.cursorrules @@ -0,0 +1,251 @@ +# Suspensive - AI Assistant Guidelines + +## Project Overview + +Suspensive is a comprehensive library ecosystem for React Suspense, providing utilities, hooks, and components to simplify working with React's Suspense feature. The project is maintained by Toss (Viva Republica, Inc.) and is open source under the MIT license. + +**Website**: https://suspensive.org +**Repository**: https://github.com/toss/suspensive +**Documentation**: https://suspensive.org/docs + +## Core Concept + +Suspensive makes React Suspense easy to use by providing: +- Declarative error boundaries with simplified fallback interfaces +- Client-only rendering utilities for SSR environments +- Enhanced Suspense components with SSR-safe features +- Integration utilities for @tanstack/react-query +- Hooks and utilities for managing async states + +## Monorepo Structure + +This is a pnpm workspace monorepo with the following key packages: + +### Main Packages (packages/) +- **@suspensive/react**: Core React Suspense utilities + - Components: ``, ``, ``, ``, `` + - Hooks: `useErrorBoundary()`, `useIsClient()`, `wrap()` + - Features: SSR-safe Suspense, simplified error boundaries, declarative loading states + +- **@suspensive/react-query**: Integration with @tanstack/react-query + - Automatically detects and supports both v4 and v5 of @tanstack/react-query + - Components: ``, ``, `` + - Hooks: `useSuspenseQuery()`, `useSuspenseInfiniteQuery()`, `useSuspenseQueries()` + - Includes CLI tools for version switching + +- **@suspensive/react-query-4**: Internal package for react-query v4 support +- **@suspensive/react-query-5**: Internal package for react-query v5 support + +- **@suspensive/react-dom**: DOM-specific utilities + - Components: ``, `` + +- **@suspensive/react-native**: React Native specific utilities + - Testing utilities for React Native environments + +- **@suspensive/next**: Next.js specific utilities + - Integration helpers for Next.js apps + +- **@suspensive/jotai**: Jotai state management integration + - Suspense-friendly Jotai utilities + +- **@suspensive/codemods**: Code transformation utilities + - CLI tool for automated migrations + - Transforms for updating Suspensive APIs + +### Configuration Packages (configs/) +- **@suspensive/tsconfig**: Shared TypeScript configurations +- **@suspensive/tsdown**: Shared build configuration using tsdown +- **@suspensive/eslint-config**: Shared ESLint configurations + +### Documentation (docs/) +- **suspensive.org**: Next.js-based documentation website with Nextra + - Multilingual support (English, Korean) + - API documentation, guides, and examples + - Located in `docs/suspensive.org/` + +### Examples (examples/) +- Working example applications demonstrating various use cases +- Include Next.js apps, Vite apps, and React Native examples + +## Technology Stack + +- **Language**: TypeScript +- **Build Tool**: tsdown (based on rolldown) +- **Package Manager**: pnpm (version managed via corepack) +- **Monorepo Tool**: Turborepo +- **Testing**: Vitest with React Testing Library +- **Documentation**: Next.js with Nextra +- **Code Quality**: ESLint, Prettier, Sherif + +## Development Workflow + +### Setup +```bash +# Enable corepack for pnpm +corepack enable && corepack prepare + +# Install dependencies +pnpm install + +# Build all packages +pnpm run build +``` + +### Common Commands +- `pnpm run build`: Build all packages +- `pnpm run dev`: Watch mode for development +- `pnpm run ci:all`: Run all CI checks (lint, type-check, test, build) +- `pnpm run ci:eslint`: Run ESLint +- `pnpm run ci:type`: Run TypeScript type checking +- `pnpm run ci:test`: Run tests +- `pnpm run format`: Format code with Prettier + +### Package-specific commands +Each package has these scripts: +- `build`: Build the package +- `ci:eslint`: Lint the package +- `ci:test`: Test the package +- `ci:type`: Type-check the package +- `clean`: Clean build artifacts + +## Code Style and Conventions + +### Naming Conventions +- Components: PascalCase (e.g., `ErrorBoundary`, `Suspense`) +- Hooks: camelCase with `use` prefix (e.g., `useErrorBoundary`, `useIsClient`) +- Utilities: camelCase (e.g., `wrap`) +- Types: PascalCase with descriptive names +- Files: Match export name (e.g., `ErrorBoundary.tsx` for ErrorBoundary component) + +### File Organization +- Each component/hook gets its own file +- Tests are co-located with source (`.spec.tsx` for runtime, `.test-d.tsx` for type tests) +- Index files (`index.ts`) export public APIs +- Internal utilities in subdirectories (e.g., `contexts/`, `hooks/`) + +### TypeScript +- Strict mode enabled +- Explicit return types for public APIs +- Generic components properly typed +- Type tests using `.test-d.tsx` files + +### React Patterns +- Functional components with TypeScript +- Props interfaces exported for extensibility +- Proper use of React.ReactNode for children +- Error boundaries as class components (React requirement) +- Hooks follow React rules + +## Key Design Principles + +1. **Simplicity**: APIs should be intuitive and easy to use +2. **Type Safety**: Strong TypeScript support with inference +3. **SSR Compatibility**: All utilities work in SSR environments +4. **Composability**: Components and hooks work well together +5. **Performance**: Minimal bundle size, tree-shakeable +6. **Developer Experience**: Great error messages and TypeScript autocomplete + +## Common Patterns + +### Error Boundary Pattern +```typescript + }> + + +``` + +### Suspense with SSR Safety +```typescript +}> + + +``` + +### React Query Integration +```typescript +const { data } = useSuspenseQuery({ queryKey: ['key'], queryFn }) +// Guaranteed to return data (no undefined handling needed) +``` + +## Testing Strategy + +- **Unit Tests**: Vitest with React Testing Library +- **Type Tests**: TypeScript compiler tests for type safety +- **Browser Tests**: @vitest/browser for DOM testing +- **Coverage**: Istanbul for code coverage + +## Documentation Guidelines + +- All public APIs must have JSDoc comments +- MDX documentation in `docs/suspensive.org/src/content/` +- Examples should be runnable and realistic +- Support both English and Korean languages +- Include migration guides for breaking changes + +## Version Management + +- Uses Changesets for version management +- Conventional Commits for commit messages +- Format: `[optional scope]: ` +- Types: feat, fix, docs, chore, test, refactor, etc. + +## Important Files + +- `package.json`: Root package configuration and scripts +- `pnpm-workspace.yaml`: Workspace configuration +- `turbo.json`: Turborepo pipeline configuration +- `tsconfig.json`: TypeScript configuration +- `.github/workflows/`: CI/CD pipelines + +## When Making Changes + +1. **Breaking Changes**: Update migration documentation +2. **New Features**: Add examples and documentation +3. **Bug Fixes**: Add regression tests +4. **Dependencies**: Use `pnpm add -w` for root, `pnpm add --filter ` for specific packages +5. **Tests**: Ensure all tests pass with `pnpm run ci:test` +6. **Type Safety**: Verify with `pnpm run ci:type` +7. **Linting**: Fix issues with `pnpm run ci:eslint` + +## Common Issues and Solutions + +### Issue: postinstall error for @suspensive/react-query +Solution: Run `pnpm run build` to build packages first + +### Issue: pnpm not found +Solution: Run `corepack enable && corepack prepare` + +### Issue: Type errors in examples +Solution: Build packages first with `pnpm run build`, examples depend on built package types + +### Issue: Test failures in CI +Solution: Ensure all packages are built before running tests + +## Package Dependencies + +- React 18+ or 19+ (peer dependency) +- @tanstack/react-query 4.42.0+ or 5.82.0+ (for react-query packages) +- Jotai (for jotai package) +- Next.js (for next package) + +## AI Assistant Specific Notes + +When assisting with this codebase: + +1. **Always check which package** you're working in - changes in one package don't affect others until rebuilt +2. **Build before testing**: The monorepo requires builds to be run before tests can access types +3. **Follow the pattern**: Look at existing components/hooks for consistent patterns +4. **Type safety matters**: Ensure all TypeScript types are correct and properly exported +5. **Documentation is required**: Update MDX docs for any API changes +6. **Examples help users**: Add or update examples when introducing new features +7. **Respect the architecture**: Don't mix concerns between packages +8. **SSR considerations**: Always consider Server-Side Rendering implications +9. **Performance matters**: Keep bundle size minimal, avoid unnecessary dependencies +10. **Community focus**: This is an open-source project - changes should benefit the broader community + +## Related Resources + +- React Suspense Docs: https://react.dev/reference/react/Suspense +- TanStack Query Docs: https://tanstack.com/query/latest +- Conventional Commits: https://www.conventionalcommits.org/ +- Changesets: https://github.com/changesets/changesets diff --git a/.github/copilot/instructions.md b/.github/copilot/instructions.md new file mode 100644 index 000000000..0ae3a0cc7 --- /dev/null +++ b/.github/copilot/instructions.md @@ -0,0 +1,180 @@ +# GitHub Copilot Instructions for Suspensive + +## Quick Context + +You are working on **Suspensive**, a library that simplifies React Suspense usage. The project provides declarative error boundaries, SSR-safe Suspense components, and integrations with @tanstack/react-query. + +## Key Architecture Points + +### Monorepo Structure +- **Main packages** in `packages/`: react, react-query, react-dom, react-native, next, jotai, codemods +- **Documentation** in `docs/suspensive.org/`: Next.js app with Nextra +- **Examples** in `examples/`: Working demo applications +- **Configs** in `configs/`: Shared configurations + +### Core Libraries +1. **@suspensive/react**: Core utilities (``, ``, ``, etc.) +2. **@suspensive/react-query**: TanStack Query integration with auto-detection for v4/v5 +3. **@suspensive/react-dom**: DOM utilities (``, ``) + +## Development Quick Start + +```bash +# Setup +corepack enable && corepack prepare +pnpm install +pnpm run build + +# Development +pnpm run dev # Watch mode +pnpm run ci:all # Full CI check +``` + +## Code Patterns to Follow + +### Component Pattern +```typescript +import type { ComponentProps, ReactNode } from 'react' + +interface MyComponentProps { + children: ReactNode + fallback?: ReactNode +} + +export const MyComponent = ({ children, fallback }: MyComponentProps) => { + // Implementation +} +``` + +### Hook Pattern +```typescript +export const useMyHook = (initialValue: T) => { + // Implementation with proper TypeScript generics +} +``` + +### Error Boundary Pattern +```typescript + ( +
+

{error.message}

+ +
+)}> + +
+``` + +## Testing Guidelines + +- Co-locate tests with source files +- Use `.spec.tsx` for runtime tests +- Use `.test-d.tsx` for type tests +- Leverage React Testing Library patterns +- Ensure SSR compatibility in tests + +## Documentation Standards + +- Update MDX docs in `docs/suspensive.org/src/content/` +- Support both English (`/en/`) and Korean (`/ko/`) +- Include runnable code examples +- Add migration guides for breaking changes + +## Common Commands by Package + +Each package supports: +- `build`: Build the package +- `ci:eslint`: Lint +- `ci:test`: Run tests +- `ci:type`: Type check + +## Important Conventions + +1. **Naming**: PascalCase for components, camelCase for hooks (with `use` prefix) +2. **Exports**: Public APIs in `index.ts`, internal utilities in subdirectories +3. **Types**: Always export prop types for extensibility +4. **SSR**: Consider server-side rendering in all implementations +5. **Bundle Size**: Keep dependencies minimal and code tree-shakeable + +## When Suggesting Code + +- Maintain consistency with existing patterns +- Ensure TypeScript types are complete and accurate +- Consider SSR implications (check for `window`, `document` usage) +- Follow React best practices (hooks rules, component patterns) +- Keep bundle size in mind +- Add appropriate JSDoc comments for public APIs + +## Package-Specific Notes + +### @suspensive/react +- Core package, no external dependencies +- Must work in SSR and CSR environments +- Focus on declarative APIs + +### @suspensive/react-query +- Auto-detects TanStack Query version (v4 or v5) +- Wraps around react-query-4 and react-query-5 packages +- Includes CLI tools for version management + +### @suspensive/react-dom +- Browser-only utilities +- Uses Intersection Observer API +- Handles viewport-based interactions + +### Documentation Site +- Built with Next.js 15 and Nextra +- Supports i18n (English and Korean) +- Uses Tailwind CSS for styling + +## Useful Patterns in Codebase + +### Wrapping Components +The library uses a pattern of wrapping React components to add functionality: +```typescript +}> + + +``` + +### Fallback Props +Consistent pattern for fallback rendering: +```typescript +fallback={({ error, reset }) => } +``` + +### SSR Safety +Use `clientOnly` prop for SSR-unsafe components: +```typescript +}> + + +``` + +## Build System + +- **Build tool**: tsdown (rolldown-based) +- **Outputs**: ESM (`.js`, `.d.ts`), CJS (`.cjs`, `.d.cts`) +- **Monorepo tool**: Turborepo with caching +- **Quality checks**: ESLint, TypeScript, Vitest + +## Don't Do + +- Don't add unnecessary dependencies +- Don't break SSR compatibility +- Don't forget to update both English and Korean docs +- Don't modify types without updating type tests +- Don't skip the build step before testing +- Don't create inconsistent API patterns +- Don't forget to add migration guides for breaking changes + +## Do + +- Follow existing patterns in the codebase +- Add comprehensive tests for new features +- Update documentation with examples +- Consider edge cases (SSR, error states, loading states) +- Keep bundle size minimal +- Maintain backward compatibility when possible +- Use TypeScript generics appropriately +- Add JSDoc comments for public APIs diff --git a/AI_DEVELOPMENT_GUIDE.md b/AI_DEVELOPMENT_GUIDE.md new file mode 100644 index 000000000..d1ddc0a1a --- /dev/null +++ b/AI_DEVELOPMENT_GUIDE.md @@ -0,0 +1,265 @@ +# AI-Friendly Project Documentation + +This file provides quick reference information for AI assistants working with the Suspensive codebase. + +## Project Identity + +**Name**: Suspensive +**Type**: React library for Suspense utilities +**License**: MIT +**Maintainer**: Toss (Viva Republica, Inc.) + +## What is Suspensive? + +Suspensive is a collection of utilities that make React Suspense easier to use. It solves common pain points: + +1. **SSR Issues**: Provides `clientOnly` prop for Suspense to avoid SSR errors +2. **Complex Error Boundaries**: Simplifies error boundary fallback interfaces +3. **TanStack Query Integration**: Provides Suspense-ready hooks for react-query + +## Quick Package Reference + +| Package | Purpose | Key Exports | +|---------|---------|-------------| +| `@suspensive/react` | Core Suspense utilities | ``, ``, ``, `` | +| `@suspensive/react-query` | React Query integration | `useSuspenseQuery()`, `` | +| `@suspensive/react-dom` | DOM utilities | ``, `` | +| `@suspensive/react-native` | React Native utilities | Testing helpers | +| `@suspensive/next` | Next.js integration | Next.js helpers | +| `@suspensive/jotai` | Jotai integration | Jotai + Suspense utilities | +| `@suspensive/codemods` | Code migrations | CLI for automated refactoring | + +## Directory Structure + +``` +suspensive/ +├── packages/ # Main library packages +│ ├── react/ # Core package +│ ├── react-query/ # TanStack Query integration +│ ├── react-query-4/ # v4 support (internal) +│ ├── react-query-5/ # v5 support (internal) +│ ├── react-dom/ # DOM utilities +│ ├── react-native/ # React Native utilities +│ ├── next/ # Next.js utilities +│ ├── jotai/ # Jotai integration +│ └── codemods/ # Code transformation tools +├── docs/ +│ └── suspensive.org/ # Documentation website (Next.js + Nextra) +├── examples/ # Example applications +├── configs/ # Shared configurations +└── .github/ # GitHub workflows and templates +``` + +## Core APIs + +### @suspensive/react + +```typescript +// Enhanced Suspense with SSR support +} clientOnly> + + + +// Simplified Error Boundary + }> + + + +// Group error boundaries + + }>... + }>... + + +// Delay showing content + + + + +// Client-only rendering +}> + + +``` + +### @suspensive/react-query + +```typescript +// Suspense-enabled query hook +const { data } = useSuspenseQuery({ + queryKey: ['key'], + queryFn: fetchData +}) +// data is always defined (no undefined checks needed) + +// Suspense-enabled infinite query +const { data, fetchNextPage } = useSuspenseInfiniteQuery({ + queryKey: ['key'], + queryFn: fetchPage +}) +``` + +### @suspensive/react-dom + +```typescript +// Intersection Observer wrapper + console.log(inView)}> + + + +// Fade in animation + + + +``` + +## Development Workflow + +### Initial Setup +```bash +# 1. Enable pnpm via corepack +corepack enable && corepack prepare + +# 2. Install dependencies +pnpm install + +# 3. Build all packages (required before running examples/tests) +pnpm run build +``` + +### Development Loop +```bash +# Watch mode for development +pnpm run dev + +# Run specific package tests +cd packages/react +pnpm run ci:test + +# Run all CI checks +pnpm run ci:all +``` + +### Making Changes +```bash +# 1. Make your changes +# 2. Build if needed +pnpm run build + +# 3. Run tests +pnpm run ci:test + +# 4. Check types +pnpm run ci:type + +# 5. Lint +pnpm run ci:eslint + +# 6. Format +pnpm run format +``` + +## Testing Philosophy + +1. **Co-located tests**: Tests live next to source files +2. **Type tests**: Use `.test-d.tsx` for TypeScript type testing +3. **Runtime tests**: Use `.spec.tsx` for behavior testing +4. **SSR testing**: Ensure components work in SSR environments +5. **Edge cases**: Test error states, loading states, and edge cases + +## TypeScript Guidelines + +- **Strict mode**: Always enabled +- **Generics**: Use for flexible, reusable components +- **Prop types**: Always export for user extensibility +- **Return types**: Explicit for public APIs +- **Type inference**: Leverage where appropriate + +## Documentation Requirements + +When adding/changing features: + +1. **Update MDX files** in `docs/suspensive.org/src/content/` +2. **Support both languages**: English (`/en/`) and Korean (`/ko/`) +3. **Add examples**: Include runnable code snippets +4. **Update README**: If it affects the package README +5. **Migration guide**: For breaking changes + +## Common Gotchas + +1. **Build first**: Must build packages before running examples or tests +2. **Monorepo**: Changes in one package don't affect others until rebuilt +3. **SSR**: Always consider server-side rendering implications +4. **Peer dependencies**: React is a peer dependency, not a direct dependency +5. **Version detection**: react-query package auto-detects TanStack Query version + +## File Naming Conventions + +- Components: `ComponentName.tsx` +- Hooks: `useHookName.ts` +- Tests: `ComponentName.spec.tsx` (runtime), `ComponentName.test-d.tsx` (types) +- Types: `types.ts` or inline with component +- Utils: `utils.ts` or `utilityName.ts` + +## Code Style + +- **Functional components**: Prefer over class components (except ErrorBoundary) +- **TypeScript**: Full type coverage +- **Named exports**: Prefer over default exports +- **Destructuring**: Use for props and state +- **Arrow functions**: Prefer for inline functions +- **Const assertions**: Use for constant objects/arrays + +## Import Conventions + +```typescript +// React imports first +import { type ReactNode, Suspense as ReactSuspense } from 'react' + +// External dependencies +import { useQuery } from '@tanstack/react-query' + +// Internal imports +import { useErrorBoundary } from './hooks' +import type { ErrorBoundaryProps } from './types' +``` + +## Performance Considerations + +- **Bundle size**: Keep it minimal, avoid large dependencies +- **Tree shaking**: Ensure code is tree-shakeable +- **Lazy loading**: Use React.lazy where appropriate +- **Memoization**: Use useMemo/useCallback judiciously +- **Re-renders**: Minimize unnecessary re-renders + +## Version Support + +- **React**: 18+ and 19+ +- **TanStack Query**: v4.42.0+ and v5.82.0+ +- **Node**: Version specified in `.nvmrc` +- **TypeScript**: Latest stable version + +## Release Process + +1. Changes are collected via Changesets +2. Version bumps follow semantic versioning +3. Changelogs auto-generated from changesets +4. Conventional commits for commit messages + +## Community Guidelines + +- **Open source**: MIT licensed, community-driven +- **Contributions**: Welcome via PRs following CONTRIBUTING.md +- **Issues**: Bug reports and feature requests via GitHub Issues +- **Discussions**: For questions and community support + +## Quick Links + +- Documentation: https://suspensive.org +- GitHub: https://github.com/toss/suspensive +- NPM: https://www.npmjs.com/package/@suspensive/react +- Discord: https://discord.gg/RFcR9WWmCH + +--- + +For detailed AI assistant guidelines, see `.cursorrules` and `.github/copilot/instructions.md` diff --git a/README.md b/README.md index c4cf5307d..036be48b9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,23 @@
+## 🤖 AI-Friendly Documentation + +Suspensive provides comprehensive AI-friendly documentation to help AI assistants understand and work with the codebase effectively: + +- **[.cursorrules](./.cursorrules)** - Complete project overview and development guidelines for AI assistants +- **[.github/copilot/instructions.md](./.github/copilot/instructions.md)** - GitHub Copilot-specific instructions and patterns +- **[AI_DEVELOPMENT_GUIDE.md](./AI_DEVELOPMENT_GUIDE.md)** - Quick reference guide for AI tools + +These resources help AI assistants: +- Understand the monorepo structure and package relationships +- Follow consistent code patterns and conventions +- Navigate the development workflow +- Make contextually appropriate suggestions +- Maintain code quality and SSR compatibility + +
+ ## Contributors Read our [Contributing Guide](./CONTRIBUTING.md) to familiarize yourself with Suspensive's development process, how to suggest bug fixes and improvements, and the steps for building and testing your changes. From 754f56f943dd89911a0107bf86257cd93085b322 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 06:40:13 +0000 Subject: [PATCH 3/4] docs: add package-level AI context files Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com> --- docs/suspensive.org/.ai-context.md | 186 ++++++++++++++++++++++++++++ packages/react-dom/.ai-context.md | 92 ++++++++++++++ packages/react-query/.ai-context.md | 123 ++++++++++++++++++ packages/react/.ai-context.md | 90 ++++++++++++++ 4 files changed, 491 insertions(+) create mode 100644 docs/suspensive.org/.ai-context.md create mode 100644 packages/react-dom/.ai-context.md create mode 100644 packages/react-query/.ai-context.md create mode 100644 packages/react/.ai-context.md diff --git a/docs/suspensive.org/.ai-context.md b/docs/suspensive.org/.ai-context.md new file mode 100644 index 000000000..f4cf05d73 --- /dev/null +++ b/docs/suspensive.org/.ai-context.md @@ -0,0 +1,186 @@ +# Documentation Site - AI Context + +## Site Purpose +Official documentation website for Suspensive libraries. Built with Next.js and Nextra for a modern, searchable documentation experience. + +## Tech Stack +- **Framework**: Next.js 15 (App Router) +- **Documentation**: Nextra (MDX-based) +- **Styling**: Tailwind CSS +- **Search**: Pagefind +- **i18n**: Built-in Next.js internationalization + +## Directory Structure + +``` +docs/suspensive.org/ +├── src/ +│ ├── app/ # Next.js app directory +│ │ └── [lang]/ # Language-specific routes +│ ├── content/ # MDX documentation files +│ │ ├── en/ # English documentation +│ │ │ └── docs/ # Organized by package +│ │ └── ko/ # Korean documentation +│ │ └── docs/ +│ ├── components/ # React components for docs +│ └── utils/ # Utility functions +├── public/ # Static assets +└── next.config.mjs # Next.js configuration +``` + +## Content Structure + +Documentation is organized by package: +- `/docs/react/` - @suspensive/react docs +- `/docs/react-query/` - @suspensive/react-query docs +- `/docs/react-dom/` - @suspensive/react-dom docs +- `/docs/codemods/` - @suspensive/codemods docs +- etc. + +Each section includes: +- `installation.mdx` - Installation guide +- `motivation.mdx` - Why the package exists +- Component/hook documentation files +- `migration/` - Migration guides + +## Languages + +- **English** (`/en/`): Primary language +- **Korean** (`/ko/`): Secondary language + +When updating docs: +1. Update English version first +2. Update Korean version with equivalent content +3. Maintain same file structure in both languages + +## MDX Features + +### Code Blocks +```tsx +// Syntax highlighting with tsx/typescript/javascript +}> + + +``` + +### Components +Import and use React components in MDX: +```mdx +import { Callout } from 'components/Callout' + + + Important note here + +``` + +### Nextra Features +- Automatic table of contents +- File-based routing +- Built-in search +- Dark mode support +- Mobile responsive + +## Building Documentation + +```bash +# Development +pnpm run dev + +# Production build +pnpm run build + +# Start production server +pnpm run start +``` + +## Writing Documentation Guidelines + +### 1. Structure +- Use clear headings (##, ###) +- Include code examples for all APIs +- Add "Why?" sections to explain motivation +- Include common use cases + +### 2. Code Examples +- Show realistic use cases +- Include imports +- Add comments for complex code +- Demonstrate both simple and advanced usage + +### 3. API Documentation +- List all props/parameters +- Specify types +- Mark required vs optional +- Include default values + +### 4. Links +- Link to related documentation +- Link to external resources (React docs, TanStack Query docs) +- Use relative links for internal pages + +## Common Patterns + +### API Documentation Page +```mdx +# ComponentName + +Brief description of what it does. + +## Installation + +Install instructions... + +## Usage + +Basic usage example... + +## Props + +| Prop | Type | Required | Default | Description | +|------|------|----------|---------|-------------| +| prop1 | string | Yes | - | What it does | + +## Examples + +### Basic Example +Code example... + +### Advanced Example +More complex example... +``` + +## Important Files + +- `next.config.mjs`: Next.js configuration with Nextra +- `src/app/[lang]/layout.tsx`: Root layout with theme provider +- `src/content/en/docs/_meta.tsx`: English docs navigation +- `src/content/ko/docs/_meta.tsx`: Korean docs navigation + +## Deployment + +Documentation is deployed via GitHub Actions: +- On push to main branch +- Deploys to suspensive.org +- Automatically runs build and deploy + +## Search + +Pagefind provides client-side search: +- Runs after build +- Indexes all documentation pages +- Supports multiple languages +- Fast, zero-network search + +## Styling + +- Uses Tailwind CSS +- Custom theme in `tailwind.config.js` +- Dark mode support via `next-themes` +- Responsive design for mobile/tablet/desktop + +## Performance + +- Static generation for all docs pages +- Optimized images with Next.js Image +- Code splitting by route +- Fast page loads with static export diff --git a/packages/react-dom/.ai-context.md b/packages/react-dom/.ai-context.md new file mode 100644 index 000000000..54fcd9e7a --- /dev/null +++ b/packages/react-dom/.ai-context.md @@ -0,0 +1,92 @@ +# @suspensive/react-dom - AI Context + +## Package Purpose +DOM-specific utilities that leverage browser APIs like Intersection Observer. Browser-only features that work with React Suspense patterns. + +## Key Components + +### `` +Wrapper using Intersection Observer API to detect when element enters viewport. + +```typescript + { + if (inView) { + console.log('Element is visible!') + } + }} + threshold={0.5} + rootMargin="10px" +> + + +``` + +**Props:** +- `onChange`: Callback when intersection state changes +- `threshold`: Visibility threshold (0-1) +- `rootMargin`: Margin around root +- `root`: Custom root element +- `triggerOnce`: Only trigger once + +### `` +Fade-in animation when component enters viewport. + +```typescript + + + +``` + +## Important Notes +- Browser-only utilities (requires DOM APIs) +- Should be wrapped in `` for SSR apps +- Uses Intersection Observer API (requires polyfill for older browsers) +- Optimized for performance with lazy observation + +## Common Patterns + +### With SSR Safety +```typescript +import { ClientOnly } from '@suspensive/react' +import { InView } from '@suspensive/react-dom' + + + console.log(inView)}> + + + +``` + +### Lazy Loading Images +```typescript + + {({ inView }) => + inView ? :
Loading...
+ } +
+``` + +### Tracking Visibility +```typescript +const [isVisible, setIsVisible] = useState(false) + + setIsVisible(inView)}> + + +``` + +## File Structure +- `src/InView.tsx` - InView component +- `src/FadeIn.tsx` - FadeIn component +- Tests co-located with components + +## Browser Compatibility +- Modern browsers with Intersection Observer support +- For older browsers, requires Intersection Observer polyfill +- Falls back gracefully when API not available + +## Performance Considerations +- Uses passive observers for scroll performance +- Automatically disconnects observers when unmounted +- Efficient for tracking multiple elements diff --git a/packages/react-query/.ai-context.md b/packages/react-query/.ai-context.md new file mode 100644 index 000000000..a83350a75 --- /dev/null +++ b/packages/react-query/.ai-context.md @@ -0,0 +1,123 @@ +# @suspensive/react-query - AI Context + +## Package Purpose +Integration layer for @tanstack/react-query that provides Suspense-enabled hooks and components. Auto-detects and supports both v4 and v5 of TanStack Query. + +## Key Features +- Suspense-enabled query hooks (data is never undefined) +- Auto-detection of TanStack Query version (v4 or v5) +- CLI tool for version management +- Zero-config switching between versions + +## Key Hooks + +### `useSuspenseQuery()` +Suspense-enabled version of useQuery. Data is always defined. +```typescript +const { data } = useSuspenseQuery({ + queryKey: ['user', id], + queryFn: () => fetchUser(id) +}) +// data is UserType, not UserType | undefined +``` + +### `useSuspenseQueries()` +Suspense-enabled version of useQueries. +```typescript +const [query1, query2] = useSuspenseQueries({ + queries: [ + { queryKey: ['user', 1], queryFn: fetchUser }, + { queryKey: ['posts'], queryFn: fetchPosts } + ] +}) +// Both query1.data and query2.data are always defined +``` + +### `useSuspenseInfiniteQuery()` +Suspense-enabled version of useInfiniteQuery. +```typescript +const { data, fetchNextPage } = useSuspenseInfiniteQuery({ + queryKey: ['posts'], + queryFn: ({ pageParam }) => fetchPosts(pageParam), + initialPageParam: 0, + getNextPageParam: (lastPage) => lastPage.nextCursor +}) +``` + +## Components + +### `` +Component version of useSuspenseQuery. +```typescript + + {({ data }) => } + +``` + +### `` +Component version of useSuspenseInfiniteQuery. + +## CLI Tools + +### Version Switching +```bash +# Check current version +pnpm suspensive-react-query version + +# Switch to v4 +pnpm suspensive-react-query switch v4 + +# Switch to v5 +pnpm suspensive-react-query switch v5 +``` + +## Architecture + +This package acts as a facade that wraps: +- `@suspensive/react-query-4` - Internal v4 implementation +- `@suspensive/react-query-5` - Internal v5 implementation + +The `postinstall` script detects which version of @tanstack/react-query is installed and configures the package accordingly. + +## Important Notes +- Depends on @tanstack/react-query (peer dependency) +- Supports v4.42.0+ and v5.82.0+ +- Version auto-detection happens at install time +- Data from Suspense hooks is guaranteed to be defined +- Must be used within QueryClientProvider + +## File Structure +- `src/index.ts` - Main entry point with version detection +- `src/v4.ts` - Exports from react-query-4 +- `src/v5.ts` - Exports from react-query-5 +- `src/bin/cli.ts` - CLI tool implementation +- `src/bin/postinstall.ts` - Version detection script + +## Common Patterns + +### With Error Boundary +```typescript +}> + }> + + + + +function Component() { + const { data } = useSuspenseQuery(...) + return
{data.name}
// data is always defined +} +``` + +### Parallel Queries +```typescript +const [users, posts] = useSuspenseQueries({ + queries: [ + { queryKey: ['users'], queryFn: fetchUsers }, + { queryKey: ['posts'], queryFn: fetchPosts } + ] +}) +``` + +## Type Safety +All hooks maintain full type inference from TanStack Query while guaranteeing non-undefined data. diff --git a/packages/react/.ai-context.md b/packages/react/.ai-context.md new file mode 100644 index 000000000..7694b544b --- /dev/null +++ b/packages/react/.ai-context.md @@ -0,0 +1,90 @@ +# @suspensive/react - AI Context + +## Package Purpose +Core React Suspense utilities that make React Suspense easier to use. This package provides SSR-safe components and simplified error boundaries. + +## Key Components + +### `` +Enhanced React.Suspense with SSR support via `clientOnly` prop. +```typescript +}> + + +``` + +### `` +Declarative error boundary with simplified fallback interface. +```typescript + }> + + +``` + +### `` +Group multiple error boundaries for coordinated reset. +```typescript + + }>... + }>... + +``` + +### `` +Delay rendering children for specified milliseconds. +```typescript + + + +``` + +### `` +Only render children on client-side. +```typescript +}> + + +``` + +## Key Hooks + +### `useErrorBoundary()` +Programmatically trigger error boundary. +```typescript +const errorBoundary = useErrorBoundary() +errorBoundary.setError(new Error('Failed')) +``` + +### `useIsClient()` +Check if code is running on client. +```typescript +const isClient = useIsClient() +``` + +## Key Utilities + +### `wrap()` +Wrap components with Suspense and ErrorBoundary. +```typescript +const wrapped = wrap + .ErrorBoundary({ fallback: }) + .Suspense({ fallback: }) + .on(MyComponent) +``` + +## Important Notes +- No external dependencies (peer dep: React only) +- Must work in both SSR and CSR +- All components are tree-shakeable +- TypeScript types are fully inferred + +## File Structure +- `src/Suspense.tsx` - Suspense component +- `src/ErrorBoundary.tsx` - ErrorBoundary component +- `src/ErrorBoundaryGroup.tsx` - ErrorBoundaryGroup component +- `src/Delay.tsx` - Delay component +- `src/ClientOnly.tsx` - ClientOnly component +- `src/hooks/` - Hook implementations +- `src/contexts/` - Context implementations +- `*.spec.tsx` - Runtime tests +- `*.test-d.tsx` - Type tests From feef5153c8f3f693d63221303b2f139d2b4c9d8c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 06:41:25 +0000 Subject: [PATCH 4/4] style: format AI documentation files with prettier --- .github/copilot/instructions.md | 18 ++++++++++++++++- AI_DEVELOPMENT_GUIDE.md | 25 +++++++++++++----------- README.md | 1 + docs/suspensive.org/.ai-context.md | 28 +++++++++++++++++++++------ packages/react-dom/.ai-context.md | 13 ++++++++++++- packages/react-query/.ai-context.md | 30 +++++++++++++++++++++++------ packages/react/.ai-context.md | 19 ++++++++++++++++++ 7 files changed, 109 insertions(+), 25 deletions(-) diff --git a/.github/copilot/instructions.md b/.github/copilot/instructions.md index 0ae3a0cc7..67bedcf5a 100644 --- a/.github/copilot/instructions.md +++ b/.github/copilot/instructions.md @@ -7,12 +7,14 @@ You are working on **Suspensive**, a library that simplifies React Suspense usag ## Key Architecture Points ### Monorepo Structure + - **Main packages** in `packages/`: react, react-query, react-dom, react-native, next, jotai, codemods - **Documentation** in `docs/suspensive.org/`: Next.js app with Nextra - **Examples** in `examples/`: Working demo applications - **Configs** in `configs/`: Shared configurations ### Core Libraries + 1. **@suspensive/react**: Core utilities (``, ``, ``, etc.) 2. **@suspensive/react-query**: TanStack Query integration with auto-detection for v4/v5 3. **@suspensive/react-dom**: DOM utilities (``, ``) @@ -33,6 +35,7 @@ pnpm run ci:all # Full CI check ## Code Patterns to Follow ### Component Pattern + ```typescript import type { ComponentProps, ReactNode } from 'react' @@ -47,13 +50,15 @@ export const MyComponent = ({ children, fallback }: MyComponentProps) => { ``` ### Hook Pattern + ```typescript -export const useMyHook = (initialValue: T) => { +export const useMyHook = (initialValue: T) => { // Implementation with proper TypeScript generics } ``` ### Error Boundary Pattern + ```typescript (
@@ -83,6 +88,7 @@ export const useMyHook = (initialValue: T) => { ## Common Commands by Package Each package supports: + - `build`: Build the package - `ci:eslint`: Lint - `ci:test`: Run tests @@ -108,21 +114,25 @@ Each package supports: ## Package-Specific Notes ### @suspensive/react + - Core package, no external dependencies - Must work in SSR and CSR environments - Focus on declarative APIs ### @suspensive/react-query + - Auto-detects TanStack Query version (v4 or v5) - Wraps around react-query-4 and react-query-5 packages - Includes CLI tools for version management ### @suspensive/react-dom + - Browser-only utilities - Uses Intersection Observer API - Handles viewport-based interactions ### Documentation Site + - Built with Next.js 15 and Nextra - Supports i18n (English and Korean) - Uses Tailwind CSS for styling @@ -130,7 +140,9 @@ Each package supports: ## Useful Patterns in Codebase ### Wrapping Components + The library uses a pattern of wrapping React components to add functionality: + ```typescript }> @@ -138,13 +150,17 @@ The library uses a pattern of wrapping React components to add functionality: ``` ### Fallback Props + Consistent pattern for fallback rendering: + ```typescript fallback={({ error, reset }) => } ``` ### SSR Safety + Use `clientOnly` prop for SSR-unsafe components: + ```typescript }> diff --git a/AI_DEVELOPMENT_GUIDE.md b/AI_DEVELOPMENT_GUIDE.md index d1ddc0a1a..96038777a 100644 --- a/AI_DEVELOPMENT_GUIDE.md +++ b/AI_DEVELOPMENT_GUIDE.md @@ -19,15 +19,15 @@ Suspensive is a collection of utilities that make React Suspense easier to use. ## Quick Package Reference -| Package | Purpose | Key Exports | -|---------|---------|-------------| -| `@suspensive/react` | Core Suspense utilities | ``, ``, ``, `` | -| `@suspensive/react-query` | React Query integration | `useSuspenseQuery()`, `` | -| `@suspensive/react-dom` | DOM utilities | ``, `` | -| `@suspensive/react-native` | React Native utilities | Testing helpers | -| `@suspensive/next` | Next.js integration | Next.js helpers | -| `@suspensive/jotai` | Jotai integration | Jotai + Suspense utilities | -| `@suspensive/codemods` | Code migrations | CLI for automated refactoring | +| Package | Purpose | Key Exports | +| -------------------------- | ----------------------- | -------------------------------------------------------------- | +| `@suspensive/react` | Core Suspense utilities | ``, ``, ``, `` | +| `@suspensive/react-query` | React Query integration | `useSuspenseQuery()`, `` | +| `@suspensive/react-dom` | DOM utilities | ``, `` | +| `@suspensive/react-native` | React Native utilities | Testing helpers | +| `@suspensive/next` | Next.js integration | Next.js helpers | +| `@suspensive/jotai` | Jotai integration | Jotai + Suspense utilities | +| `@suspensive/codemods` | Code migrations | CLI for automated refactoring | ## Directory Structure @@ -88,14 +88,14 @@ suspensive/ // Suspense-enabled query hook const { data } = useSuspenseQuery({ queryKey: ['key'], - queryFn: fetchData + queryFn: fetchData, }) // data is always defined (no undefined checks needed) // Suspense-enabled infinite query const { data, fetchNextPage } = useSuspenseInfiniteQuery({ queryKey: ['key'], - queryFn: fetchPage + queryFn: fetchPage, }) ``` @@ -116,6 +116,7 @@ const { data, fetchNextPage } = useSuspenseInfiniteQuery({ ## Development Workflow ### Initial Setup + ```bash # 1. Enable pnpm via corepack corepack enable && corepack prepare @@ -128,6 +129,7 @@ pnpm run build ``` ### Development Loop + ```bash # Watch mode for development pnpm run dev @@ -141,6 +143,7 @@ pnpm run ci:all ``` ### Making Changes + ```bash # 1. Make your changes # 2. Build if needed diff --git a/README.md b/README.md index 036be48b9..331bee3b2 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Suspensive provides comprehensive AI-friendly documentation to help AI assistant - **[AI_DEVELOPMENT_GUIDE.md](./AI_DEVELOPMENT_GUIDE.md)** - Quick reference guide for AI tools These resources help AI assistants: + - Understand the monorepo structure and package relationships - Follow consistent code patterns and conventions - Navigate the development workflow diff --git a/docs/suspensive.org/.ai-context.md b/docs/suspensive.org/.ai-context.md index f4cf05d73..eb102fef4 100644 --- a/docs/suspensive.org/.ai-context.md +++ b/docs/suspensive.org/.ai-context.md @@ -1,9 +1,11 @@ # Documentation Site - AI Context ## Site Purpose + Official documentation website for Suspensive libraries. Built with Next.js and Nextra for a modern, searchable documentation experience. ## Tech Stack + - **Framework**: Next.js 15 (App Router) - **Documentation**: Nextra (MDX-based) - **Styling**: Tailwind CSS @@ -31,6 +33,7 @@ docs/suspensive.org/ ## Content Structure Documentation is organized by package: + - `/docs/react/` - @suspensive/react docs - `/docs/react-query/` - @suspensive/react-query docs - `/docs/react-dom/` - @suspensive/react-dom docs @@ -38,6 +41,7 @@ Documentation is organized by package: - etc. Each section includes: + - `installation.mdx` - Installation guide - `motivation.mdx` - Why the package exists - Component/hook documentation files @@ -49,6 +53,7 @@ Each section includes: - **Korean** (`/ko/`): Secondary language When updating docs: + 1. Update English version first 2. Update Korean version with equivalent content 3. Maintain same file structure in both languages @@ -56,6 +61,7 @@ When updating docs: ## MDX Features ### Code Blocks + ```tsx // Syntax highlighting with tsx/typescript/javascript }> @@ -64,16 +70,17 @@ When updating docs: ``` ### Components + Import and use React components in MDX: + ```mdx import { Callout } from 'components/Callout' - - Important note here - +Important note here ``` ### Nextra Features + - Automatic table of contents - File-based routing - Built-in search @@ -96,24 +103,28 @@ pnpm run start ## Writing Documentation Guidelines ### 1. Structure + - Use clear headings (##, ###) - Include code examples for all APIs - Add "Why?" sections to explain motivation - Include common use cases ### 2. Code Examples + - Show realistic use cases - Include imports - Add comments for complex code - Demonstrate both simple and advanced usage ### 3. API Documentation + - List all props/parameters - Specify types - Mark required vs optional - Include default values ### 4. Links + - Link to related documentation - Link to external resources (React docs, TanStack Query docs) - Use relative links for internal pages @@ -121,6 +132,7 @@ pnpm run start ## Common Patterns ### API Documentation Page + ```mdx # ComponentName @@ -136,16 +148,18 @@ Basic usage example... ## Props -| Prop | Type | Required | Default | Description | -|------|------|----------|---------|-------------| -| prop1 | string | Yes | - | What it does | +| Prop | Type | Required | Default | Description | +| ----- | ------ | -------- | ------- | ------------ | +| prop1 | string | Yes | - | What it does | ## Examples ### Basic Example + Code example... ### Advanced Example + More complex example... ``` @@ -159,6 +173,7 @@ More complex example... ## Deployment Documentation is deployed via GitHub Actions: + - On push to main branch - Deploys to suspensive.org - Automatically runs build and deploy @@ -166,6 +181,7 @@ Documentation is deployed via GitHub Actions: ## Search Pagefind provides client-side search: + - Runs after build - Indexes all documentation pages - Supports multiple languages diff --git a/packages/react-dom/.ai-context.md b/packages/react-dom/.ai-context.md index 54fcd9e7a..c0ec8e587 100644 --- a/packages/react-dom/.ai-context.md +++ b/packages/react-dom/.ai-context.md @@ -1,11 +1,13 @@ # @suspensive/react-dom - AI Context ## Package Purpose + DOM-specific utilities that leverage browser APIs like Intersection Observer. Browser-only features that work with React Suspense patterns. ## Key Components ### `` + Wrapper using Intersection Observer API to detect when element enters viewport. ```typescript @@ -23,6 +25,7 @@ Wrapper using Intersection Observer API to detect when element enters viewport. ``` **Props:** + - `onChange`: Callback when intersection state changes - `threshold`: Visibility threshold (0-1) - `rootMargin`: Margin around root @@ -30,6 +33,7 @@ Wrapper using Intersection Observer API to detect when element enters viewport. - `triggerOnce`: Only trigger once ### `` + Fade-in animation when component enters viewport. ```typescript @@ -39,6 +43,7 @@ Fade-in animation when component enters viewport. ``` ## Important Notes + - Browser-only utilities (requires DOM APIs) - Should be wrapped in `` for SSR apps - Uses Intersection Observer API (requires polyfill for older browsers) @@ -47,6 +52,7 @@ Fade-in animation when component enters viewport. ## Common Patterns ### With SSR Safety + ```typescript import { ClientOnly } from '@suspensive/react' import { InView } from '@suspensive/react-dom' @@ -59,15 +65,17 @@ import { InView } from '@suspensive/react-dom' ``` ### Lazy Loading Images + ```typescript - {({ inView }) => + {({ inView }) => inView ? :
Loading...
}
``` ### Tracking Visibility + ```typescript const [isVisible, setIsVisible] = useState(false) @@ -77,16 +85,19 @@ const [isVisible, setIsVisible] = useState(false) ``` ## File Structure + - `src/InView.tsx` - InView component - `src/FadeIn.tsx` - FadeIn component - Tests co-located with components ## Browser Compatibility + - Modern browsers with Intersection Observer support - For older browsers, requires Intersection Observer polyfill - Falls back gracefully when API not available ## Performance Considerations + - Uses passive observers for scroll performance - Automatically disconnects observers when unmounted - Efficient for tracking multiple elements diff --git a/packages/react-query/.ai-context.md b/packages/react-query/.ai-context.md index a83350a75..ad502b51d 100644 --- a/packages/react-query/.ai-context.md +++ b/packages/react-query/.ai-context.md @@ -1,9 +1,11 @@ # @suspensive/react-query - AI Context ## Package Purpose + Integration layer for @tanstack/react-query that provides Suspense-enabled hooks and components. Auto-detects and supports both v4 and v5 of TanStack Query. ## Key Features + - Suspense-enabled query hooks (data is never undefined) - Auto-detection of TanStack Query version (v4 or v5) - CLI tool for version management @@ -12,42 +14,50 @@ Integration layer for @tanstack/react-query that provides Suspense-enabled hooks ## Key Hooks ### `useSuspenseQuery()` + Suspense-enabled version of useQuery. Data is always defined. + ```typescript const { data } = useSuspenseQuery({ queryKey: ['user', id], - queryFn: () => fetchUser(id) + queryFn: () => fetchUser(id), }) // data is UserType, not UserType | undefined ``` ### `useSuspenseQueries()` + Suspense-enabled version of useQueries. + ```typescript const [query1, query2] = useSuspenseQueries({ queries: [ { queryKey: ['user', 1], queryFn: fetchUser }, - { queryKey: ['posts'], queryFn: fetchPosts } - ] + { queryKey: ['posts'], queryFn: fetchPosts }, + ], }) // Both query1.data and query2.data are always defined ``` ### `useSuspenseInfiniteQuery()` + Suspense-enabled version of useInfiniteQuery. + ```typescript const { data, fetchNextPage } = useSuspenseInfiniteQuery({ queryKey: ['posts'], queryFn: ({ pageParam }) => fetchPosts(pageParam), initialPageParam: 0, - getNextPageParam: (lastPage) => lastPage.nextCursor + getNextPageParam: (lastPage) => lastPage.nextCursor, }) ``` ## Components ### `` + Component version of useSuspenseQuery. + ```typescript {({ data }) => } @@ -55,11 +65,13 @@ Component version of useSuspenseQuery. ``` ### `` + Component version of useSuspenseInfiniteQuery. ## CLI Tools ### Version Switching + ```bash # Check current version pnpm suspensive-react-query version @@ -74,12 +86,14 @@ pnpm suspensive-react-query switch v5 ## Architecture This package acts as a facade that wraps: + - `@suspensive/react-query-4` - Internal v4 implementation - `@suspensive/react-query-5` - Internal v5 implementation The `postinstall` script detects which version of @tanstack/react-query is installed and configures the package accordingly. ## Important Notes + - Depends on @tanstack/react-query (peer dependency) - Supports v4.42.0+ and v5.82.0+ - Version auto-detection happens at install time @@ -87,6 +101,7 @@ The `postinstall` script detects which version of @tanstack/react-query is insta - Must be used within QueryClientProvider ## File Structure + - `src/index.ts` - Main entry point with version detection - `src/v4.ts` - Exports from react-query-4 - `src/v5.ts` - Exports from react-query-5 @@ -96,6 +111,7 @@ The `postinstall` script detects which version of @tanstack/react-query is insta ## Common Patterns ### With Error Boundary + ```typescript }> }> @@ -110,14 +126,16 @@ function Component() { ``` ### Parallel Queries + ```typescript const [users, posts] = useSuspenseQueries({ queries: [ { queryKey: ['users'], queryFn: fetchUsers }, - { queryKey: ['posts'], queryFn: fetchPosts } - ] + { queryKey: ['posts'], queryFn: fetchPosts }, + ], }) ``` ## Type Safety + All hooks maintain full type inference from TanStack Query while guaranteeing non-undefined data. diff --git a/packages/react/.ai-context.md b/packages/react/.ai-context.md index 7694b544b..8de1eb952 100644 --- a/packages/react/.ai-context.md +++ b/packages/react/.ai-context.md @@ -1,12 +1,15 @@ # @suspensive/react - AI Context ## Package Purpose + Core React Suspense utilities that make React Suspense easier to use. This package provides SSR-safe components and simplified error boundaries. ## Key Components ### `` + Enhanced React.Suspense with SSR support via `clientOnly` prop. + ```typescript }> @@ -14,7 +17,9 @@ Enhanced React.Suspense with SSR support via `clientOnly` prop. ``` ### `` + Declarative error boundary with simplified fallback interface. + ```typescript }> @@ -22,7 +27,9 @@ Declarative error boundary with simplified fallback interface. ``` ### `` + Group multiple error boundaries for coordinated reset. + ```typescript }>... @@ -31,7 +38,9 @@ Group multiple error boundaries for coordinated reset. ``` ### `` + Delay rendering children for specified milliseconds. + ```typescript @@ -39,7 +48,9 @@ Delay rendering children for specified milliseconds. ``` ### `` + Only render children on client-side. + ```typescript }> @@ -49,14 +60,18 @@ Only render children on client-side. ## Key Hooks ### `useErrorBoundary()` + Programmatically trigger error boundary. + ```typescript const errorBoundary = useErrorBoundary() errorBoundary.setError(new Error('Failed')) ``` ### `useIsClient()` + Check if code is running on client. + ```typescript const isClient = useIsClient() ``` @@ -64,7 +79,9 @@ const isClient = useIsClient() ## Key Utilities ### `wrap()` + Wrap components with Suspense and ErrorBoundary. + ```typescript const wrapped = wrap .ErrorBoundary({ fallback: }) @@ -73,12 +90,14 @@ const wrapped = wrap ``` ## Important Notes + - No external dependencies (peer dep: React only) - Must work in both SSR and CSR - All components are tree-shakeable - TypeScript types are fully inferred ## File Structure + - `src/Suspense.tsx` - Suspense component - `src/ErrorBoundary.tsx` - ErrorBoundary component - `src/ErrorBoundaryGroup.tsx` - ErrorBoundaryGroup component