create-huenei-template 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/templates.js +7 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/accessibility-reviewer.md +22 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/nextjs-code-reviewer.md +24 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/react-test-expert.md +32 -0
- package/dist/templates/frontend/react-ssr/.cursor/agents/security-auditor.md +25 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-component.md +97 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-page.md +95 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-prisma-model.md +66 -0
- package/dist/templates/frontend/react-ssr/.cursor/commands/new-server-action.md +89 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/auto-format.ts +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/auto-test-on-stop.ts +94 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/block-dangerous-commands.ts +120 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/ensure-tests-exist.ts +209 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/protect-sensitive-files.ts +101 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/session-context.ts +93 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks/tsconfig.json +10 -0
- package/dist/templates/frontend/react-ssr/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/auth-patterns.mdc +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/code-quality.mdc +39 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/naming-conventions.mdc +32 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/nextjs-architecture.mdc +51 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/prisma-standards.mdc +53 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/react-conventions.mdc +52 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/testing-conventions.mdc +53 -0
- package/dist/templates/frontend/react-ssr/.cursor/rules/ui-stack.mdc +47 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/authjs-skills/SKILL.md +1149 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/SKILL.md +189 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/daisyUI5.skill +0 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/creating-components.md +412 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/data-display.md +341 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/feedback.md +240 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/input.md +283 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/layout.md +275 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/navigation.md +338 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/daisy-meta.ts +220 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/generate-daisy-safelist.ts +152 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/docker-expert/SKILL.md +413 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/nextjs-app-router-patterns/SKILL.md +537 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/SKILL.md +243 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-execute.md +75 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-pull.md +185 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-push.md +148 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-seed.md +191 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/debug.md +46 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/dev.md +157 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/format.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/generate.md +147 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/init.md +118 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-deploy.md +127 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-dev.md +143 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-diff.md +89 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-reset.md +72 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-resolve.md +57 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-status.md +65 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/studio.md +122 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/validate.md +53 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/SKILL.md +216 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/client-methods.md +221 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/constructor.md +185 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/filters.md +256 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/model-queries.md +281 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/query-options.md +276 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/raw-queries.md +194 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/relations.md +308 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/transactions.md +184 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/AGENTS.md +97 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/README.md +138 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/SKILL.md +116 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/assets/templates/_template.md +26 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/_sections.md +46 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-devtools-performance.md +69 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-formprovider-memo.md +78 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-testing-wrapper.md +63 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-complete-default-objects.md +66 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-separate-crud-operations.md +76 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-unique-fieldarray-per-name.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-use-field-id-as-key.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-virtualization-formprovider.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-avoid-double-registration.md +46 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-controller-field-props.md +56 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-local-state-combination.md +69 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-single-usecontroller-per-component.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-usecontroller-isolation.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-async-default-values.md +69 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-default-values.md +57 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-revalidate-mode.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-should-unregister.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-useeffect-dependency.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-validation-mode.md +51 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-avoid-isvalid-with-onsubmit.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-destructure-formstate.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-getfieldstate-for-single-field.md +49 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-subscribe-to-specific-fields.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-useformstate-isolation.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-mui-controller-pattern.md +59 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-form-import.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-select-wiring.md +64 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-value-transform.md +59 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-avoid-watch-in-render.md +48 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-deep-subscription.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-useformcontext-sparingly.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-default-value.md +50 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-over-watch.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-with-getvalues.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-watch-specific-fields.md +54 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-delay-error.md +52 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-dynamic-schema-factory.md +57 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-error-message-strategy.md +65 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-inline-vs-resolver.md +63 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-native-validation.md +60 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-resolver-caching.md +58 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/SKILL.md +713 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/references/api_reference.md +1121 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/references/best_practices.md +782 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/recharts/references/examples.md +940 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/SKILL.md +114 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-gc-time.md +93 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-invalidation.md +116 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-placeholder-vs-initial.md +156 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-stale-time.md +80 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/err-error-boundaries.md +150 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/inf-page-params.md +132 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-invalidate-queries.md +118 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-mutation-state.md +169 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-optimistic-updates.md +137 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/network-mode.md +179 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/parallel-use-queries.md +152 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/perf-select-transform.md +144 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/persist-queries.md +194 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/pf-intent-prefetch.md +143 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-array-structure.md +50 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-factory-pattern.md +102 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-hierarchical-organization.md +76 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-include-dependencies.md +62 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-serializable.md +93 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/query-cancellation.md +171 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/ssr-dehydration.md +158 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/tanstack-table/SKILL.md +582 -0
- package/dist/templates/frontend/react-ssr/.cursor/skills/zod-4/SKILL.md +216 -0
- package/dist/templates/frontend/react-ssr/.dockerignore +14 -0
- package/dist/templates/frontend/react-ssr/.env.example +9 -0
- package/dist/templates/frontend/react-ssr/.husky/pre-commit +1 -0
- package/dist/templates/frontend/react-ssr/Dockerfile +41 -0
- package/dist/templates/frontend/react-ssr/README.md +121 -0
- package/dist/templates/frontend/react-ssr/components.json +22 -0
- package/dist/templates/frontend/react-ssr/docker-compose.yml +21 -0
- package/dist/templates/frontend/react-ssr/eslint.config.mjs +26 -0
- package/dist/templates/frontend/react-ssr/next.config.ts +7 -0
- package/dist/templates/frontend/react-ssr/package.json +86 -0
- package/dist/templates/frontend/react-ssr/postcss.config.mjs +5 -0
- package/dist/templates/frontend/react-ssr/prisma/schema.prisma +75 -0
- package/dist/templates/frontend/react-ssr/prisma/seed.ts +109 -0
- package/dist/templates/frontend/react-ssr/prisma.config.ts +17 -0
- package/dist/templates/frontend/react-ssr/skills-lock.json +65 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/badge.test.tsx +26 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/button.test.tsx +38 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/card.test.tsx +39 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/components/ui/input.test.tsx +32 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/hooks/useLocalStorage.test.ts +53 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/lib/queryClient.test.ts +19 -0
- package/dist/templates/frontend/react-ssr/src/__tests__/lib/utils.test.ts +24 -0
- package/dist/templates/frontend/react-ssr/src/actions/auth.ts +91 -0
- package/dist/templates/frontend/react-ssr/src/actions/contacto.ts +46 -0
- package/dist/templates/frontend/react-ssr/src/actions/proyectos.ts +159 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/dashboard-client.tsx +321 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/page.tsx +48 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/layout.tsx +34 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/perfil/page.tsx +85 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/page.tsx +23 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/proyectos-crud-client.tsx +472 -0
- package/dist/templates/frontend/react-ssr/src/app/(authenticated)/ui-components/page.tsx +358 -0
- package/dist/templates/frontend/react-ssr/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/dist/templates/frontend/react-ssr/src/app/auth/iniciar-sesion/page.tsx +148 -0
- package/dist/templates/frontend/react-ssr/src/app/auth/recuperar-password/page.tsx +100 -0
- package/dist/templates/frontend/react-ssr/src/app/auth/registro/page.tsx +154 -0
- package/dist/templates/frontend/react-ssr/src/app/contacto/contacto-form.tsx +189 -0
- package/dist/templates/frontend/react-ssr/src/app/contacto/page.tsx +11 -0
- package/dist/templates/frontend/react-ssr/src/app/globals.css +99 -0
- package/dist/templates/frontend/react-ssr/src/app/layout.tsx +22 -0
- package/dist/templates/frontend/react-ssr/src/app/loading.tsx +7 -0
- package/dist/templates/frontend/react-ssr/src/app/not-found.tsx +14 -0
- package/dist/templates/frontend/react-ssr/src/app/page.tsx +331 -0
- package/dist/templates/frontend/react-ssr/src/app/proyectos/page.tsx +178 -0
- package/dist/templates/frontend/react-ssr/src/auth.ts +64 -0
- package/dist/templates/frontend/react-ssr/src/components/layout/navbar.tsx +68 -0
- package/dist/templates/frontend/react-ssr/src/components/layout/sidebar.tsx +109 -0
- package/dist/templates/frontend/react-ssr/src/components/layout/sign-out-button.tsx +16 -0
- package/dist/templates/frontend/react-ssr/src/components/providers.tsx +33 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/avatar.tsx +53 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/badge.tsx +42 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/breadcrumb.tsx +114 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/button.tsx +58 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/card.tsx +95 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/dialog.tsx +136 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/form.tsx +168 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/input.tsx +22 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/label.tsx +26 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/password-input.tsx +43 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/separator.tsx +30 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/table.tsx +240 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/tabs.tsx +76 -0
- package/dist/templates/frontend/react-ssr/src/components/ui/textarea.tsx +21 -0
- package/dist/templates/frontend/react-ssr/src/data/dashboard.ts +179 -0
- package/dist/templates/frontend/react-ssr/src/hooks/useLocalStorage.ts +38 -0
- package/dist/templates/frontend/react-ssr/src/lib/prisma.ts +24 -0
- package/dist/templates/frontend/react-ssr/src/lib/queryClient.ts +25 -0
- package/dist/templates/frontend/react-ssr/src/lib/utils.ts +6 -0
- package/dist/templates/frontend/react-ssr/src/proxy.ts +31 -0
- package/dist/templates/frontend/react-ssr/src/test/mocks/next-navigation.ts +16 -0
- package/dist/templates/frontend/react-ssr/src/test/setup.ts +1 -0
- package/dist/templates/frontend/react-ssr/src/test/utils.tsx +30 -0
- package/dist/templates/frontend/react-ssr/src/types/index.ts +36 -0
- package/dist/templates/frontend/react-ssr/tsconfig.json +41 -0
- package/dist/templates/frontend/react-ssr/vitest.config.ts +41 -0
- package/package.json +1 -1
- package/templates/frontend/react-ssr/.cursor/agents/accessibility-reviewer.md +22 -0
- package/templates/frontend/react-ssr/.cursor/agents/nextjs-code-reviewer.md +24 -0
- package/templates/frontend/react-ssr/.cursor/agents/react-test-expert.md +32 -0
- package/templates/frontend/react-ssr/.cursor/agents/security-auditor.md +25 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-component.md +97 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-page.md +95 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-prisma-model.md +66 -0
- package/templates/frontend/react-ssr/.cursor/commands/new-server-action.md +89 -0
- package/templates/frontend/react-ssr/.cursor/hooks/auto-format.ts +64 -0
- package/templates/frontend/react-ssr/.cursor/hooks/auto-test-on-stop.ts +94 -0
- package/templates/frontend/react-ssr/.cursor/hooks/block-dangerous-commands.ts +120 -0
- package/templates/frontend/react-ssr/.cursor/hooks/ensure-tests-exist.ts +209 -0
- package/templates/frontend/react-ssr/.cursor/hooks/protect-sensitive-files.ts +101 -0
- package/templates/frontend/react-ssr/.cursor/hooks/session-context.ts +93 -0
- package/templates/frontend/react-ssr/.cursor/hooks/tsconfig.json +10 -0
- package/templates/frontend/react-ssr/.cursor/hooks.json +41 -0
- package/templates/frontend/react-ssr/.cursor/rules/auth-patterns.mdc +48 -0
- package/templates/frontend/react-ssr/.cursor/rules/code-quality.mdc +39 -0
- package/templates/frontend/react-ssr/.cursor/rules/naming-conventions.mdc +32 -0
- package/templates/frontend/react-ssr/.cursor/rules/nextjs-architecture.mdc +51 -0
- package/templates/frontend/react-ssr/.cursor/rules/prisma-standards.mdc +53 -0
- package/templates/frontend/react-ssr/.cursor/rules/react-conventions.mdc +52 -0
- package/templates/frontend/react-ssr/.cursor/rules/testing-conventions.mdc +53 -0
- package/templates/frontend/react-ssr/.cursor/rules/ui-stack.mdc +47 -0
- package/templates/frontend/react-ssr/.cursor/skills/authjs-skills/SKILL.md +1149 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/SKILL.md +189 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/daisyUI5.skill +0 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/creating-components.md +412 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/data-display.md +341 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/feedback.md +240 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/input.md +283 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/layout.md +275 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/references/navigation.md +338 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/daisy-meta.ts +220 -0
- package/templates/frontend/react-ssr/.cursor/skills/daisyui-5/scripts/generate-daisy-safelist.ts +152 -0
- package/templates/frontend/react-ssr/.cursor/skills/docker-expert/SKILL.md +413 -0
- package/templates/frontend/react-ssr/.cursor/skills/nextjs-app-router-patterns/SKILL.md +537 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/SKILL.md +243 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-execute.md +75 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-pull.md +185 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-push.md +148 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/db-seed.md +191 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/debug.md +46 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/dev.md +157 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/format.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/generate.md +147 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/init.md +118 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-deploy.md +127 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-dev.md +143 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-diff.md +89 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-reset.md +72 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-resolve.md +57 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/migrate-status.md +65 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/studio.md +122 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-cli/references/validate.md +53 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/SKILL.md +216 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/client-methods.md +221 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/constructor.md +185 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/filters.md +256 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/model-queries.md +281 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/query-options.md +276 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/raw-queries.md +194 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/relations.md +308 -0
- package/templates/frontend/react-ssr/.cursor/skills/prisma-client-api/references/transactions.md +184 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/AGENTS.md +97 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/README.md +138 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/SKILL.md +116 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/assets/templates/_template.md +26 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/_sections.md +46 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-devtools-performance.md +69 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-formprovider-memo.md +78 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/adv-testing-wrapper.md +63 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-complete-default-objects.md +66 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-separate-crud-operations.md +76 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-unique-fieldarray-per-name.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-use-field-id-as-key.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/array-virtualization-formprovider.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-avoid-double-registration.md +46 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-controller-field-props.md +56 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-local-state-combination.md +69 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-single-usecontroller-per-component.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/ctrl-usecontroller-isolation.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-async-default-values.md +69 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-default-values.md +57 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-revalidate-mode.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-should-unregister.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-useeffect-dependency.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formcfg-validation-mode.md +51 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-avoid-isvalid-with-onsubmit.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-destructure-formstate.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-getfieldstate-for-single-field.md +49 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-subscribe-to-specific-fields.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/formstate-useformstate-isolation.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-mui-controller-pattern.md +59 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-form-import.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-shadcn-select-wiring.md +64 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/integ-value-transform.md +59 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-avoid-watch-in-render.md +48 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-deep-subscription.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-useformcontext-sparingly.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-default-value.md +50 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-over-watch.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-usewatch-with-getvalues.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/sub-watch-specific-fields.md +54 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-delay-error.md +52 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-dynamic-schema-factory.md +57 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-error-message-strategy.md +65 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-inline-vs-resolver.md +63 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-native-validation.md +60 -0
- package/templates/frontend/react-ssr/.cursor/skills/react-hook-form/references/valid-resolver-caching.md +58 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/SKILL.md +713 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/references/api_reference.md +1121 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/references/best_practices.md +782 -0
- package/templates/frontend/react-ssr/.cursor/skills/recharts/references/examples.md +940 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/SKILL.md +114 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-gc-time.md +93 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-invalidation.md +116 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-placeholder-vs-initial.md +156 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/cache-stale-time.md +80 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/err-error-boundaries.md +150 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/inf-page-params.md +132 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-invalidate-queries.md +118 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-mutation-state.md +169 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/mut-optimistic-updates.md +137 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/network-mode.md +179 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/parallel-use-queries.md +152 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/perf-select-transform.md +144 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/persist-queries.md +194 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/pf-intent-prefetch.md +143 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-array-structure.md +50 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-factory-pattern.md +102 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-hierarchical-organization.md +76 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-include-dependencies.md +62 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/qk-serializable.md +93 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/query-cancellation.md +171 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-query-best-practices/rules/ssr-dehydration.md +158 -0
- package/templates/frontend/react-ssr/.cursor/skills/tanstack-table/SKILL.md +582 -0
- package/templates/frontend/react-ssr/.cursor/skills/zod-4/SKILL.md +216 -0
- package/templates/frontend/react-ssr/.dockerignore +14 -0
- package/templates/frontend/react-ssr/.env.example +9 -0
- package/templates/frontend/react-ssr/.husky/pre-commit +1 -0
- package/templates/frontend/react-ssr/Dockerfile +41 -0
- package/templates/frontend/react-ssr/README.md +121 -0
- package/templates/frontend/react-ssr/components.json +22 -0
- package/templates/frontend/react-ssr/docker-compose.yml +21 -0
- package/templates/frontend/react-ssr/eslint.config.mjs +26 -0
- package/templates/frontend/react-ssr/next.config.ts +7 -0
- package/templates/frontend/react-ssr/package.json +86 -0
- package/templates/frontend/react-ssr/postcss.config.mjs +5 -0
- package/templates/frontend/react-ssr/prisma/schema.prisma +75 -0
- package/templates/frontend/react-ssr/prisma/seed.ts +109 -0
- package/templates/frontend/react-ssr/prisma.config.ts +17 -0
- package/templates/frontend/react-ssr/skills-lock.json +65 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/badge.test.tsx +26 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/button.test.tsx +38 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/card.test.tsx +39 -0
- package/templates/frontend/react-ssr/src/__tests__/components/ui/input.test.tsx +32 -0
- package/templates/frontend/react-ssr/src/__tests__/hooks/useLocalStorage.test.ts +53 -0
- package/templates/frontend/react-ssr/src/__tests__/lib/queryClient.test.ts +19 -0
- package/templates/frontend/react-ssr/src/__tests__/lib/utils.test.ts +24 -0
- package/templates/frontend/react-ssr/src/actions/auth.ts +91 -0
- package/templates/frontend/react-ssr/src/actions/contacto.ts +46 -0
- package/templates/frontend/react-ssr/src/actions/proyectos.ts +159 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/dashboard-client.tsx +321 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/dashboard/page.tsx +48 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/layout.tsx +34 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/perfil/page.tsx +85 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/page.tsx +23 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/proyectos-crud/proyectos-crud-client.tsx +472 -0
- package/templates/frontend/react-ssr/src/app/(authenticated)/ui-components/page.tsx +358 -0
- package/templates/frontend/react-ssr/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/templates/frontend/react-ssr/src/app/auth/iniciar-sesion/page.tsx +148 -0
- package/templates/frontend/react-ssr/src/app/auth/recuperar-password/page.tsx +100 -0
- package/templates/frontend/react-ssr/src/app/auth/registro/page.tsx +154 -0
- package/templates/frontend/react-ssr/src/app/contacto/contacto-form.tsx +189 -0
- package/templates/frontend/react-ssr/src/app/contacto/page.tsx +11 -0
- package/templates/frontend/react-ssr/src/app/globals.css +99 -0
- package/templates/frontend/react-ssr/src/app/layout.tsx +22 -0
- package/templates/frontend/react-ssr/src/app/loading.tsx +7 -0
- package/templates/frontend/react-ssr/src/app/not-found.tsx +14 -0
- package/templates/frontend/react-ssr/src/app/page.tsx +331 -0
- package/templates/frontend/react-ssr/src/app/proyectos/page.tsx +178 -0
- package/templates/frontend/react-ssr/src/auth.ts +64 -0
- package/templates/frontend/react-ssr/src/components/layout/navbar.tsx +68 -0
- package/templates/frontend/react-ssr/src/components/layout/sidebar.tsx +109 -0
- package/templates/frontend/react-ssr/src/components/layout/sign-out-button.tsx +16 -0
- package/templates/frontend/react-ssr/src/components/providers.tsx +33 -0
- package/templates/frontend/react-ssr/src/components/ui/avatar.tsx +53 -0
- package/templates/frontend/react-ssr/src/components/ui/badge.tsx +42 -0
- package/templates/frontend/react-ssr/src/components/ui/breadcrumb.tsx +114 -0
- package/templates/frontend/react-ssr/src/components/ui/button.tsx +58 -0
- package/templates/frontend/react-ssr/src/components/ui/card.tsx +95 -0
- package/templates/frontend/react-ssr/src/components/ui/dialog.tsx +136 -0
- package/templates/frontend/react-ssr/src/components/ui/form.tsx +168 -0
- package/templates/frontend/react-ssr/src/components/ui/input.tsx +22 -0
- package/templates/frontend/react-ssr/src/components/ui/label.tsx +26 -0
- package/templates/frontend/react-ssr/src/components/ui/password-input.tsx +43 -0
- package/templates/frontend/react-ssr/src/components/ui/separator.tsx +30 -0
- package/templates/frontend/react-ssr/src/components/ui/table.tsx +240 -0
- package/templates/frontend/react-ssr/src/components/ui/tabs.tsx +76 -0
- package/templates/frontend/react-ssr/src/components/ui/textarea.tsx +21 -0
- package/templates/frontend/react-ssr/src/data/dashboard.ts +179 -0
- package/templates/frontend/react-ssr/src/hooks/useLocalStorage.ts +38 -0
- package/templates/frontend/react-ssr/src/lib/prisma.ts +24 -0
- package/templates/frontend/react-ssr/src/lib/queryClient.ts +25 -0
- package/templates/frontend/react-ssr/src/lib/utils.ts +6 -0
- package/templates/frontend/react-ssr/src/proxy.ts +31 -0
- package/templates/frontend/react-ssr/src/test/mocks/next-navigation.ts +16 -0
- package/templates/frontend/react-ssr/src/test/setup.ts +1 -0
- package/templates/frontend/react-ssr/src/test/utils.tsx +30 -0
- package/templates/frontend/react-ssr/src/types/index.ts +36 -0
- package/templates/frontend/react-ssr/tsconfig.json +41 -0
- package/templates/frontend/react-ssr/vitest.config.ts +41 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# err-error-boundaries: Use Error Boundaries with useQueryErrorResetBoundary
|
|
2
|
+
|
|
3
|
+
## Priority: HIGH
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
When using Suspense with TanStack Query, errors propagate to error boundaries. Use `useQueryErrorResetBoundary` to reset query errors when users retry, preventing stuck error states.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Error boundary without query reset - retry may not work
|
|
13
|
+
function ErrorBoundary({ children }: { children: React.ReactNode }) {
|
|
14
|
+
return (
|
|
15
|
+
<ReactErrorBoundary
|
|
16
|
+
fallbackRender={({ error, resetErrorBoundary }) => (
|
|
17
|
+
<div>
|
|
18
|
+
<p>Error: {error.message}</p>
|
|
19
|
+
<button onClick={resetErrorBoundary}>Try again</button>
|
|
20
|
+
{/* resetErrorBoundary alone doesn't reset query state */}
|
|
21
|
+
</div>
|
|
22
|
+
)}
|
|
23
|
+
>
|
|
24
|
+
{children}
|
|
25
|
+
</ReactErrorBoundary>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Query error persists after retry click
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Good Example
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { useQueryErrorResetBoundary } from '@tanstack/react-query'
|
|
36
|
+
import { ErrorBoundary } from 'react-error-boundary'
|
|
37
|
+
|
|
38
|
+
function QueryErrorBoundary({ children }: { children: React.ReactNode }) {
|
|
39
|
+
const { reset } = useQueryErrorResetBoundary()
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<ErrorBoundary
|
|
43
|
+
onReset={reset}
|
|
44
|
+
fallbackRender={({ error, resetErrorBoundary }) => (
|
|
45
|
+
<div className="error-container">
|
|
46
|
+
<h2>Something went wrong</h2>
|
|
47
|
+
<pre>{error.message}</pre>
|
|
48
|
+
<button onClick={resetErrorBoundary}>
|
|
49
|
+
Try again
|
|
50
|
+
</button>
|
|
51
|
+
</div>
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
{children}
|
|
55
|
+
</ErrorBoundary>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Usage with Suspense
|
|
60
|
+
function App() {
|
|
61
|
+
return (
|
|
62
|
+
<QueryErrorBoundary>
|
|
63
|
+
<Suspense fallback={<Loading />}>
|
|
64
|
+
<Posts />
|
|
65
|
+
</Suspense>
|
|
66
|
+
</QueryErrorBoundary>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function Posts() {
|
|
71
|
+
// useSuspenseQuery throws on error, caught by boundary
|
|
72
|
+
const { data } = useSuspenseQuery({
|
|
73
|
+
queryKey: ['posts'],
|
|
74
|
+
queryFn: fetchPosts,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
return <PostList posts={data} />
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Good Example: With TanStack Router
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
// Route-level error handling
|
|
85
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
86
|
+
import { useQueryErrorResetBoundary } from '@tanstack/react-query'
|
|
87
|
+
|
|
88
|
+
export const Route = createFileRoute('/posts')({
|
|
89
|
+
loader: ({ context: { queryClient } }) =>
|
|
90
|
+
queryClient.ensureQueryData(postQueries.list()),
|
|
91
|
+
|
|
92
|
+
errorComponent: ({ error, reset }) => {
|
|
93
|
+
const { reset: resetQuery } = useQueryErrorResetBoundary()
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div>
|
|
97
|
+
<p>Failed to load posts: {error.message}</p>
|
|
98
|
+
<button
|
|
99
|
+
onClick={() => {
|
|
100
|
+
resetQuery()
|
|
101
|
+
reset()
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
Retry
|
|
105
|
+
</button>
|
|
106
|
+
</div>
|
|
107
|
+
)
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
component: PostsPage,
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Error Boundary Placement Strategy
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
// Granular error boundaries for isolated failures
|
|
118
|
+
function Dashboard() {
|
|
119
|
+
return (
|
|
120
|
+
<div className="dashboard">
|
|
121
|
+
{/* Each section can fail independently */}
|
|
122
|
+
<QueryErrorBoundary>
|
|
123
|
+
<Suspense fallback={<Skeleton />}>
|
|
124
|
+
<RecentActivity />
|
|
125
|
+
</Suspense>
|
|
126
|
+
</QueryErrorBoundary>
|
|
127
|
+
|
|
128
|
+
<QueryErrorBoundary>
|
|
129
|
+
<Suspense fallback={<Skeleton />}>
|
|
130
|
+
<Statistics />
|
|
131
|
+
</Suspense>
|
|
132
|
+
</QueryErrorBoundary>
|
|
133
|
+
|
|
134
|
+
<QueryErrorBoundary>
|
|
135
|
+
<Suspense fallback={<Skeleton />}>
|
|
136
|
+
<Notifications />
|
|
137
|
+
</Suspense>
|
|
138
|
+
</QueryErrorBoundary>
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Context
|
|
145
|
+
|
|
146
|
+
- `useQueryErrorResetBoundary` clears error state for all queries in the boundary
|
|
147
|
+
- Always pair Suspense queries with error boundaries
|
|
148
|
+
- Place boundaries based on failure isolation needs
|
|
149
|
+
- Consider inline error handling for non-critical data
|
|
150
|
+
- The reset only affects queries that were in error state
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# inf-page-params: Always Provide getNextPageParam for Infinite Queries
|
|
2
|
+
|
|
3
|
+
## Priority: MEDIUM
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
`useInfiniteQuery` requires `getNextPageParam` to determine how to fetch subsequent pages. This function receives the last page's data and must return the next page parameter, or `undefined` when there are no more pages.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Missing getNextPageParam - can't load more pages
|
|
13
|
+
const { data, fetchNextPage } = useInfiniteQuery({
|
|
14
|
+
queryKey: ['posts'],
|
|
15
|
+
queryFn: ({ pageParam }) => fetchPosts(pageParam),
|
|
16
|
+
initialPageParam: 1,
|
|
17
|
+
// Missing getNextPageParam - fetchNextPage won't work correctly
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Good Example: Offset-Based Pagination
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
const {
|
|
25
|
+
data,
|
|
26
|
+
fetchNextPage,
|
|
27
|
+
hasNextPage,
|
|
28
|
+
isFetchingNextPage,
|
|
29
|
+
} = useInfiniteQuery({
|
|
30
|
+
queryKey: ['posts'],
|
|
31
|
+
queryFn: ({ pageParam }) => fetchPosts({ page: pageParam, limit: 20 }),
|
|
32
|
+
initialPageParam: 1,
|
|
33
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
34
|
+
// Return next page number, or undefined if no more pages
|
|
35
|
+
if (lastPage.length < 20) {
|
|
36
|
+
return undefined // No more pages
|
|
37
|
+
}
|
|
38
|
+
return allPages.length + 1
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Good Example: Cursor-Based Pagination
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
interface PostsResponse {
|
|
47
|
+
posts: Post[]
|
|
48
|
+
nextCursor: string | null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { data, fetchNextPage, hasNextPage } = useInfiniteQuery({
|
|
52
|
+
queryKey: ['posts'],
|
|
53
|
+
queryFn: ({ pageParam }): Promise<PostsResponse> =>
|
|
54
|
+
fetchPosts({ cursor: pageParam }),
|
|
55
|
+
initialPageParam: undefined as string | undefined,
|
|
56
|
+
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Good Example: Bi-directional Pagination
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
const { data, fetchNextPage, fetchPreviousPage, hasNextPage, hasPreviousPage } =
|
|
64
|
+
useInfiniteQuery({
|
|
65
|
+
queryKey: ['messages', chatId],
|
|
66
|
+
queryFn: ({ pageParam }) => fetchMessages({ chatId, cursor: pageParam }),
|
|
67
|
+
initialPageParam: { direction: 'initial' } as PageParam,
|
|
68
|
+
getNextPageParam: (lastPage) =>
|
|
69
|
+
lastPage.hasMore ? { cursor: lastPage.nextCursor, direction: 'next' } : undefined,
|
|
70
|
+
getPreviousPageParam: (firstPage) =>
|
|
71
|
+
firstPage.hasPrevious
|
|
72
|
+
? { cursor: firstPage.prevCursor, direction: 'prev' }
|
|
73
|
+
: undefined,
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Good Example: With Total Count
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
interface PaginatedResponse<T> {
|
|
81
|
+
items: T[]
|
|
82
|
+
total: number
|
|
83
|
+
page: number
|
|
84
|
+
pageSize: number
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const { data, hasNextPage } = useInfiniteQuery({
|
|
88
|
+
queryKey: ['products', filters],
|
|
89
|
+
queryFn: ({ pageParam }) =>
|
|
90
|
+
fetchProducts({ ...filters, page: pageParam, pageSize: 20 }),
|
|
91
|
+
initialPageParam: 1,
|
|
92
|
+
getNextPageParam: (lastPage) => {
|
|
93
|
+
const totalPages = Math.ceil(lastPage.total / lastPage.pageSize)
|
|
94
|
+
if (lastPage.page < totalPages) {
|
|
95
|
+
return lastPage.page + 1
|
|
96
|
+
}
|
|
97
|
+
return undefined
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Accessing Flattened Data
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
// data.pages is an array of page responses
|
|
106
|
+
// Flatten for easier iteration
|
|
107
|
+
const allPosts = data?.pages.flatMap(page => page.posts) ?? []
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
{allPosts.map(post => (
|
|
112
|
+
<PostCard key={post.id} post={post} />
|
|
113
|
+
))}
|
|
114
|
+
{hasNextPage && (
|
|
115
|
+
<button
|
|
116
|
+
onClick={() => fetchNextPage()}
|
|
117
|
+
disabled={isFetchingNextPage}
|
|
118
|
+
>
|
|
119
|
+
{isFetchingNextPage ? 'Loading...' : 'Load More'}
|
|
120
|
+
</button>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Context
|
|
127
|
+
|
|
128
|
+
- `getNextPageParam` returning `undefined` sets `hasNextPage` to `false`
|
|
129
|
+
- For bi-directional scrolling, also provide `getPreviousPageParam`
|
|
130
|
+
- `initialPageParam` is required and sets the first page parameter
|
|
131
|
+
- Use `maxPages` option to limit stored pages for memory management
|
|
132
|
+
- Consider `select` to transform page structure for component consumption
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# mut-invalidate-queries: Always Invalidate Related Queries After Mutations
|
|
2
|
+
|
|
3
|
+
## Priority: HIGH
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
After mutations, invalidate all queries whose data might be affected. This ensures the cache stays synchronized with the server. Forgetting to invalidate related queries leads to stale UI data.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// No invalidation - cache remains stale
|
|
13
|
+
const createTodo = useMutation({
|
|
14
|
+
mutationFn: (newTodo) => api.createTodo(newTodo),
|
|
15
|
+
// Missing onSuccess handler - todo list won't show new item
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
// Partial invalidation - misses related queries
|
|
19
|
+
const deleteTodo = useMutation({
|
|
20
|
+
mutationFn: (todoId) => api.deleteTodo(todoId),
|
|
21
|
+
onSuccess: () => {
|
|
22
|
+
// Only invalidates list, not summary/counts
|
|
23
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 'list'] })
|
|
24
|
+
// Missing: ['todos', 'count'], ['todos', 'completed-count'], etc.
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Good Example
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// Comprehensive invalidation
|
|
33
|
+
const createTodo = useMutation({
|
|
34
|
+
mutationFn: (newTodo) => api.createTodo(newTodo),
|
|
35
|
+
onSuccess: () => {
|
|
36
|
+
// Invalidate all todo-related queries
|
|
37
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
// Targeted invalidation with all affected queries
|
|
42
|
+
const updateTodo = useMutation({
|
|
43
|
+
mutationFn: ({ id, data }) => api.updateTodo(id, data),
|
|
44
|
+
onSuccess: (data, { id }) => {
|
|
45
|
+
// Specific todo
|
|
46
|
+
queryClient.invalidateQueries({ queryKey: ['todos', id] })
|
|
47
|
+
// Lists that might contain this todo
|
|
48
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 'list'] })
|
|
49
|
+
// If todo status changed, invalidate filtered views
|
|
50
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 'completed'] })
|
|
51
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 'active'] })
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// Cross-entity invalidation
|
|
56
|
+
const assignTodoToUser = useMutation({
|
|
57
|
+
mutationFn: ({ todoId, userId }) => api.assignTodo(todoId, userId),
|
|
58
|
+
onSuccess: (data, { todoId, userId }) => {
|
|
59
|
+
// Invalidate the todo
|
|
60
|
+
queryClient.invalidateQueries({ queryKey: ['todos', todoId] })
|
|
61
|
+
// Invalidate user's assigned todos
|
|
62
|
+
queryClient.invalidateQueries({ queryKey: ['users', userId, 'todos'] })
|
|
63
|
+
// Invalidate previous assignee's list if available
|
|
64
|
+
if (data.previousAssignee) {
|
|
65
|
+
queryClient.invalidateQueries({
|
|
66
|
+
queryKey: ['users', data.previousAssignee, 'todos'],
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Pattern: Mutation with Variables Access
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
const mutation = useMutation({
|
|
77
|
+
mutationFn: updatePost,
|
|
78
|
+
onSuccess: (
|
|
79
|
+
data, // Server response
|
|
80
|
+
variables, // What you passed to mutate()
|
|
81
|
+
context // What onMutate returned
|
|
82
|
+
) => {
|
|
83
|
+
// Use variables to know which queries to invalidate
|
|
84
|
+
queryClient.invalidateQueries({ queryKey: ['posts', variables.id] })
|
|
85
|
+
queryClient.invalidateQueries({ queryKey: ['posts', 'list', variables.category] })
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Pattern: Invalidate or Update Directly
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
// Option 1: Invalidate and refetch
|
|
94
|
+
onSuccess: () => {
|
|
95
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Option 2: Update cache directly (no network request)
|
|
99
|
+
onSuccess: (newTodo) => {
|
|
100
|
+
queryClient.setQueryData(['todos'], (old: Todo[]) => [...old, newTodo])
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Option 3: Hybrid - update one, invalidate others
|
|
104
|
+
onSuccess: (newTodo) => {
|
|
105
|
+
// Immediately add to list
|
|
106
|
+
queryClient.setQueryData(['todos', 'list'], (old: Todo[]) => [...old, newTodo])
|
|
107
|
+
// Invalidate counts/summaries for eventual consistency
|
|
108
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 'count'] })
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Context
|
|
113
|
+
|
|
114
|
+
- Place invalidation in `onSuccess` for successful mutations
|
|
115
|
+
- Use `onSettled` if you want to invalidate regardless of success/failure
|
|
116
|
+
- Think about all UI surfaces that display related data
|
|
117
|
+
- For complex relationships, consider a centralized invalidation helper
|
|
118
|
+
- Using hierarchical query keys makes this easier (see `qk-hierarchical-organization`)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# mut-mutation-state: Use useMutationState for Cross-Component Mutation Tracking
|
|
2
|
+
|
|
3
|
+
## Priority: MEDIUM
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
`useMutationState` allows you to access mutation state from anywhere in your component tree, not just where `useMutation` was called. Use it to show loading indicators, display optimistic updates, or track pending mutations across components.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Prop drilling mutation state
|
|
13
|
+
function App() {
|
|
14
|
+
const mutation = useMutation({ mutationFn: createPost })
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div>
|
|
18
|
+
<Header isPending={mutation.isPending} />
|
|
19
|
+
<Sidebar isPending={mutation.isPending} />
|
|
20
|
+
<Content mutation={mutation} />
|
|
21
|
+
<Footer isPending={mutation.isPending} />
|
|
22
|
+
</div>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Or using context for every mutation
|
|
27
|
+
const MutationContext = createContext<UseMutationResult | null>(null)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Good Example
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
// Define mutation with a key
|
|
34
|
+
const useCreatePost = () => useMutation({
|
|
35
|
+
mutationKey: ['create-post'],
|
|
36
|
+
mutationFn: createPost,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// In the component that triggers mutation
|
|
40
|
+
function CreatePostButton() {
|
|
41
|
+
const mutation = useCreatePost()
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<button onClick={() => mutation.mutate(newPost)}>
|
|
45
|
+
Create Post
|
|
46
|
+
</button>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// In any other component - track mutation state
|
|
51
|
+
function GlobalLoadingIndicator() {
|
|
52
|
+
const pendingMutations = useMutationState({
|
|
53
|
+
filters: { status: 'pending' },
|
|
54
|
+
select: (mutation) => mutation.state.variables,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
if (pendingMutations.length === 0) return null
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="global-loading">
|
|
61
|
+
Saving {pendingMutations.length} item(s)...
|
|
62
|
+
</div>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Good Example: Optimistic UI in Separate Component
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
// Mutation defined in form
|
|
71
|
+
function TodoForm() {
|
|
72
|
+
const createTodo = useMutation({
|
|
73
|
+
mutationKey: ['create-todo'],
|
|
74
|
+
mutationFn: (todo: NewTodo) => api.createTodo(todo),
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
return <form onSubmit={...}>...</form>
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Optimistic display in list (different component)
|
|
81
|
+
function TodoList() {
|
|
82
|
+
const { data: todos } = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
|
|
83
|
+
|
|
84
|
+
// Get pending todo creations
|
|
85
|
+
const pendingTodos = useMutationState({
|
|
86
|
+
filters: {
|
|
87
|
+
mutationKey: ['create-todo'],
|
|
88
|
+
status: 'pending',
|
|
89
|
+
},
|
|
90
|
+
select: (mutation) => mutation.state.variables as NewTodo,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<ul>
|
|
95
|
+
{/* Existing todos */}
|
|
96
|
+
{todos?.map(todo => (
|
|
97
|
+
<TodoItem key={todo.id} todo={todo} />
|
|
98
|
+
))}
|
|
99
|
+
|
|
100
|
+
{/* Optimistic todos (pending creation) */}
|
|
101
|
+
{pendingTodos.map((todo, index) => (
|
|
102
|
+
<TodoItem
|
|
103
|
+
key={`pending-${index}`}
|
|
104
|
+
todo={{ ...todo, id: `temp-${index}` }}
|
|
105
|
+
isPending
|
|
106
|
+
/>
|
|
107
|
+
))}
|
|
108
|
+
</ul>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Good Example: Track Specific Mutations
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
function PostActions({ postId }: { postId: string }) {
|
|
117
|
+
// Track if THIS post is being deleted
|
|
118
|
+
const isDeletingThisPost = useMutationState({
|
|
119
|
+
filters: {
|
|
120
|
+
mutationKey: ['delete-post', postId],
|
|
121
|
+
status: 'pending',
|
|
122
|
+
},
|
|
123
|
+
select: () => true,
|
|
124
|
+
}).length > 0
|
|
125
|
+
|
|
126
|
+
// Track if THIS post is being updated
|
|
127
|
+
const isUpdatingThisPost = useMutationState({
|
|
128
|
+
filters: {
|
|
129
|
+
mutationKey: ['update-post', postId],
|
|
130
|
+
status: 'pending',
|
|
131
|
+
},
|
|
132
|
+
select: () => true,
|
|
133
|
+
}).length > 0
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div>
|
|
137
|
+
<button disabled={isDeletingThisPost || isUpdatingThisPost}>
|
|
138
|
+
{isDeletingThisPost ? 'Deleting...' : 'Delete'}
|
|
139
|
+
</button>
|
|
140
|
+
</div>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Filters Reference
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
useMutationState({
|
|
149
|
+
filters: {
|
|
150
|
+
mutationKey: ['key'], // Match mutation key
|
|
151
|
+
status: 'pending', // 'idle' | 'pending' | 'success' | 'error'
|
|
152
|
+
predicate: (mutation) => bool, // Custom filter function
|
|
153
|
+
},
|
|
154
|
+
select: (mutation) => {
|
|
155
|
+
// Transform each matching mutation
|
|
156
|
+
// mutation.state contains: variables, data, error, status, etc.
|
|
157
|
+
return mutation.state.variables
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Context
|
|
163
|
+
|
|
164
|
+
- Requires `mutationKey` on mutations you want to track
|
|
165
|
+
- Returns array of selected values from matching mutations
|
|
166
|
+
- Updates reactively as mutations progress
|
|
167
|
+
- Use `status` filter to track pending/success/error states
|
|
168
|
+
- Enables optimistic UI without prop drilling
|
|
169
|
+
- Pairs with `mutationKey` arrays for granular tracking (e.g., `['delete-post', postId]`)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# mut-optimistic-updates: Implement Optimistic Updates for Responsive UI
|
|
2
|
+
|
|
3
|
+
## Priority: HIGH
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
Optimistic updates immediately reflect changes in the UI before the server confirms them, creating a snappy user experience. Implement them for user-initiated mutations where the expected outcome is predictable.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// No optimistic update - UI waits for server response
|
|
13
|
+
const mutation = useMutation({
|
|
14
|
+
mutationFn: toggleTodoComplete,
|
|
15
|
+
onSuccess: () => {
|
|
16
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// User clicks checkbox, waits 200-500ms for visual feedback
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Good Example: Via Cache Manipulation
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
const mutation = useMutation({
|
|
27
|
+
mutationFn: toggleTodoComplete,
|
|
28
|
+
onMutate: async (todoId) => {
|
|
29
|
+
// 1. Cancel outgoing refetches to prevent overwriting optimistic update
|
|
30
|
+
await queryClient.cancelQueries({ queryKey: ['todos'] })
|
|
31
|
+
|
|
32
|
+
// 2. Snapshot previous value for potential rollback
|
|
33
|
+
const previousTodos = queryClient.getQueryData(['todos'])
|
|
34
|
+
|
|
35
|
+
// 3. Optimistically update the cache
|
|
36
|
+
queryClient.setQueryData(['todos'], (old: Todo[]) =>
|
|
37
|
+
old.map((todo) =>
|
|
38
|
+
todo.id === todoId ? { ...todo, completed: !todo.completed } : todo
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
// 4. Return context for rollback
|
|
43
|
+
return { previousTodos }
|
|
44
|
+
},
|
|
45
|
+
onError: (err, todoId, context) => {
|
|
46
|
+
// Rollback on error
|
|
47
|
+
queryClient.setQueryData(['todos'], context?.previousTodos)
|
|
48
|
+
},
|
|
49
|
+
onSettled: () => {
|
|
50
|
+
// Refetch to ensure consistency regardless of success/failure
|
|
51
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Good Example: Via UI Variables (Simpler)
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
// When mutation only affects local UI, use mutation state directly
|
|
60
|
+
function TodoItem({ todo }: { todo: Todo }) {
|
|
61
|
+
const mutation = useMutation({
|
|
62
|
+
mutationFn: toggleTodoComplete,
|
|
63
|
+
onSuccess: () => {
|
|
64
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Show optimistic state while pending
|
|
69
|
+
const displayCompleted = mutation.isPending
|
|
70
|
+
? !todo.completed // Optimistic: show toggled state
|
|
71
|
+
: todo.completed // Settled: show actual state
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div>
|
|
75
|
+
<input
|
|
76
|
+
type="checkbox"
|
|
77
|
+
checked={displayCompleted}
|
|
78
|
+
disabled={mutation.isPending}
|
|
79
|
+
onChange={() => mutation.mutate(todo.id)}
|
|
80
|
+
/>
|
|
81
|
+
<span style={{ opacity: mutation.isPending ? 0.5 : 1 }}>
|
|
82
|
+
{todo.title}
|
|
83
|
+
</span>
|
|
84
|
+
</div>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Good Example: Optimistic Create with Temporary ID
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
const createTodo = useMutation({
|
|
93
|
+
mutationFn: (newTodo: CreateTodoInput) => api.createTodo(newTodo),
|
|
94
|
+
onMutate: async (newTodo) => {
|
|
95
|
+
await queryClient.cancelQueries({ queryKey: ['todos'] })
|
|
96
|
+
const previousTodos = queryClient.getQueryData(['todos'])
|
|
97
|
+
|
|
98
|
+
// Add with temporary ID
|
|
99
|
+
const optimisticTodo = {
|
|
100
|
+
id: `temp-${Date.now()}`,
|
|
101
|
+
...newTodo,
|
|
102
|
+
completed: false,
|
|
103
|
+
createdAt: new Date().toISOString(),
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
queryClient.setQueryData(['todos'], (old: Todo[]) => [...old, optimisticTodo])
|
|
107
|
+
|
|
108
|
+
return { previousTodos, optimisticTodo }
|
|
109
|
+
},
|
|
110
|
+
onError: (err, newTodo, context) => {
|
|
111
|
+
queryClient.setQueryData(['todos'], context?.previousTodos)
|
|
112
|
+
},
|
|
113
|
+
onSuccess: (data, variables, context) => {
|
|
114
|
+
// Replace temp todo with real one
|
|
115
|
+
queryClient.setQueryData(['todos'], (old: Todo[]) =>
|
|
116
|
+
old.map((todo) =>
|
|
117
|
+
todo.id === context?.optimisticTodo.id ? data : todo
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## When to Use Each Approach
|
|
125
|
+
|
|
126
|
+
| Approach | Use When |
|
|
127
|
+
|----------|----------|
|
|
128
|
+
| Cache Manipulation | Update appears in multiple places, complex data structures |
|
|
129
|
+
| UI Variables | Update only visible in one component, simpler implementation |
|
|
130
|
+
|
|
131
|
+
## Context
|
|
132
|
+
|
|
133
|
+
- Always provide rollback logic in `onError`
|
|
134
|
+
- Cancel queries before optimistic update to prevent race conditions
|
|
135
|
+
- Call `invalidateQueries` in `onSettled` to sync with server truth
|
|
136
|
+
- For forms, consider if validation should block optimistic display
|
|
137
|
+
- Test error scenarios to verify rollback works correctly
|