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