create-huenei-template 0.2.13 → 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/cursor/.cursor/agents/config-drift-analyzer.md +152 -0
- package/dist/templates/cursor/.cursor/commands/actualizar-reglas.md +580 -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/cursor/.cursor/agents/config-drift-analyzer.md +152 -0
- package/templates/cursor/.cursor/commands/actualizar-reglas.md +580 -0
- 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,143 @@
|
|
|
1
|
+
# pf-intent-prefetch: Prefetch on User Intent (Hover, Focus)
|
|
2
|
+
|
|
3
|
+
## Priority: MEDIUM
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
Prefetch data when users show intent to navigate (hover, focus) rather than waiting for click. This eliminates perceived loading time for likely next actions.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// No prefetching - data fetches on click
|
|
13
|
+
function PostList({ posts }: { posts: Post[] }) {
|
|
14
|
+
return (
|
|
15
|
+
<ul>
|
|
16
|
+
{posts.map(post => (
|
|
17
|
+
<li key={post.id}>
|
|
18
|
+
<Link to={`/posts/${post.id}`}>
|
|
19
|
+
{post.title}
|
|
20
|
+
</Link>
|
|
21
|
+
{/* User clicks, waits for data to load */}
|
|
22
|
+
</li>
|
|
23
|
+
))}
|
|
24
|
+
</ul>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Good Example
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
33
|
+
import { postQueries } from '@/lib/queries'
|
|
34
|
+
|
|
35
|
+
function PostList({ posts }: { posts: Post[] }) {
|
|
36
|
+
const queryClient = useQueryClient()
|
|
37
|
+
|
|
38
|
+
const handlePrefetch = (postId: number) => {
|
|
39
|
+
queryClient.prefetchQuery({
|
|
40
|
+
...postQueries.detail(postId),
|
|
41
|
+
staleTime: 60 * 1000, // Consider fresh for 1 minute
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<ul>
|
|
47
|
+
{posts.map(post => (
|
|
48
|
+
<li key={post.id}>
|
|
49
|
+
<Link
|
|
50
|
+
to={`/posts/${post.id}`}
|
|
51
|
+
onMouseEnter={() => handlePrefetch(post.id)}
|
|
52
|
+
onFocus={() => handlePrefetch(post.id)}
|
|
53
|
+
>
|
|
54
|
+
{post.title}
|
|
55
|
+
</Link>
|
|
56
|
+
</li>
|
|
57
|
+
))}
|
|
58
|
+
</ul>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Good Example: With TanStack Router
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { Link } from '@tanstack/react-router'
|
|
67
|
+
|
|
68
|
+
// TanStack Router has built-in prefetching
|
|
69
|
+
function PostList({ posts }: { posts: Post[] }) {
|
|
70
|
+
return (
|
|
71
|
+
<ul>
|
|
72
|
+
{posts.map(post => (
|
|
73
|
+
<li key={post.id}>
|
|
74
|
+
<Link
|
|
75
|
+
to="/posts/$postId"
|
|
76
|
+
params={{ postId: post.id }}
|
|
77
|
+
preload="intent" // Prefetch on hover/focus
|
|
78
|
+
>
|
|
79
|
+
{post.title}
|
|
80
|
+
</Link>
|
|
81
|
+
</li>
|
|
82
|
+
))}
|
|
83
|
+
</ul>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Or set as router default
|
|
88
|
+
const router = createRouter({
|
|
89
|
+
routeTree,
|
|
90
|
+
defaultPreload: 'intent',
|
|
91
|
+
defaultPreloadDelay: 100, // Wait 100ms before prefetching
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Good Example: Prefetch with Delay
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
function PostLink({ post }: { post: Post }) {
|
|
99
|
+
const queryClient = useQueryClient()
|
|
100
|
+
const timeoutRef = useRef<NodeJS.Timeout>()
|
|
101
|
+
|
|
102
|
+
const handleMouseEnter = () => {
|
|
103
|
+
// Delay prefetch to avoid unnecessary requests on quick mouse movements
|
|
104
|
+
timeoutRef.current = setTimeout(() => {
|
|
105
|
+
queryClient.prefetchQuery(postQueries.detail(post.id))
|
|
106
|
+
}, 100)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const handleMouseLeave = () => {
|
|
110
|
+
if (timeoutRef.current) {
|
|
111
|
+
clearTimeout(timeoutRef.current)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<Link
|
|
117
|
+
to={`/posts/${post.id}`}
|
|
118
|
+
onMouseEnter={handleMouseEnter}
|
|
119
|
+
onMouseLeave={handleMouseLeave}
|
|
120
|
+
>
|
|
121
|
+
{post.title}
|
|
122
|
+
</Link>
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Prefetch Triggers
|
|
128
|
+
|
|
129
|
+
| Trigger | When to Use |
|
|
130
|
+
|---------|-------------|
|
|
131
|
+
| `onMouseEnter` | Desktop, links/buttons user will likely click |
|
|
132
|
+
| `onFocus` | Keyboard navigation, accessibility |
|
|
133
|
+
| `onTouchStart` | Mobile, before navigation |
|
|
134
|
+
| Component mount | Likely next pages, wizard steps |
|
|
135
|
+
| Intersection Observer | Below-fold content |
|
|
136
|
+
|
|
137
|
+
## Context
|
|
138
|
+
|
|
139
|
+
- Set appropriate `staleTime` when prefetching to avoid immediate refetch
|
|
140
|
+
- Consider mobile where hover isn't available
|
|
141
|
+
- Don't prefetch everything - focus on likely paths
|
|
142
|
+
- Prefetched data uses `gcTime` for retention
|
|
143
|
+
- Watch network tab to verify prefetch timing
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# qk-array-structure: Always Use Arrays for Query Keys
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
Query keys must always be arrays at the top level. This enables proper caching, invalidation matching, and query deduplication. Using non-array keys will cause unexpected behavior and cache misses.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Never use strings or non-array types as query keys
|
|
13
|
+
const { data } = useQuery({
|
|
14
|
+
queryKey: 'todos', // Wrong: string instead of array
|
|
15
|
+
queryFn: fetchTodos,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const { data: user } = useQuery({
|
|
19
|
+
queryKey: { id: 1, type: 'user' }, // Wrong: object instead of array
|
|
20
|
+
queryFn: fetchUser,
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Good Example
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
// Always use arrays for query keys
|
|
28
|
+
const { data } = useQuery({
|
|
29
|
+
queryKey: ['todos'],
|
|
30
|
+
queryFn: fetchTodos,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const { data: user } = useQuery({
|
|
34
|
+
queryKey: ['user', 1],
|
|
35
|
+
queryFn: () => fetchUser(1),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Complex keys with objects inside arrays are fine
|
|
39
|
+
const { data: filteredTodos } = useQuery({
|
|
40
|
+
queryKey: ['todos', { status: 'done', page: 1 }],
|
|
41
|
+
queryFn: () => fetchTodos({ status: 'done', page: 1 }),
|
|
42
|
+
})
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Context
|
|
46
|
+
|
|
47
|
+
- Always applicable when defining query keys
|
|
48
|
+
- Arrays enable prefix-based invalidation (e.g., `invalidateQueries({ queryKey: ['todos'] })` matches all todo queries)
|
|
49
|
+
- Object property order inside arrays doesn't matter for matching
|
|
50
|
+
- Array element order does matter: `['todos', 1]` !== `['1', 'todos']`
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# qk-factory-pattern: Use Query Key Factories for Complex Applications
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
For applications with many queries, centralize query key definitions in factory functions. This ensures consistency, enables autocomplete, prevents typos, and makes refactoring safer. Query key factories are the recommended pattern for production applications.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Scattered, inconsistent key definitions across files
|
|
13
|
+
// file: components/TodoList.tsx
|
|
14
|
+
const { data } = useQuery({
|
|
15
|
+
queryKey: ['todos', 'list'],
|
|
16
|
+
queryFn: fetchTodos,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// file: components/TodoDetail.tsx
|
|
20
|
+
const { data } = useQuery({
|
|
21
|
+
queryKey: ['todo', id], // Inconsistent: 'todo' vs 'todos'
|
|
22
|
+
queryFn: () => fetchTodo(id),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// file: components/TodoComments.tsx
|
|
26
|
+
const { data } = useQuery({
|
|
27
|
+
queryKey: ['todoComments', todoId], // Different naming convention
|
|
28
|
+
queryFn: () => fetchComments(todoId),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Invalidation is error-prone
|
|
32
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] }) // Misses 'todo' and 'todoComments'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Good Example
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
// file: lib/query-keys.ts
|
|
39
|
+
export const todoKeys = {
|
|
40
|
+
all: ['todos'] as const,
|
|
41
|
+
lists: () => [...todoKeys.all, 'list'] as const,
|
|
42
|
+
list: (filters: TodoFilters) => [...todoKeys.lists(), filters] as const,
|
|
43
|
+
details: () => [...todoKeys.all, 'detail'] as const,
|
|
44
|
+
detail: (id: number) => [...todoKeys.details(), id] as const,
|
|
45
|
+
comments: (id: number) => [...todoKeys.detail(id), 'comments'] as const,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const userKeys = {
|
|
49
|
+
all: ['users'] as const,
|
|
50
|
+
detail: (id: string) => [...userKeys.all, id] as const,
|
|
51
|
+
posts: (id: string) => [...userKeys.detail(id), 'posts'] as const,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// file: components/TodoList.tsx
|
|
55
|
+
import { todoKeys } from '@/lib/query-keys'
|
|
56
|
+
|
|
57
|
+
const { data } = useQuery({
|
|
58
|
+
queryKey: todoKeys.list({ status: 'active' }),
|
|
59
|
+
queryFn: () => fetchTodos({ status: 'active' }),
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// file: components/TodoDetail.tsx
|
|
63
|
+
const { data } = useQuery({
|
|
64
|
+
queryKey: todoKeys.detail(id),
|
|
65
|
+
queryFn: () => fetchTodo(id),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Invalidation is type-safe and predictable
|
|
69
|
+
queryClient.invalidateQueries({ queryKey: todoKeys.all }) // Invalidates everything
|
|
70
|
+
queryClient.invalidateQueries({ queryKey: todoKeys.detail(5) }) // Specific todo + comments
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Query Options Factory Pattern
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
// Even better: combine with queryOptions for full type safety
|
|
77
|
+
import { queryOptions } from '@tanstack/react-query'
|
|
78
|
+
|
|
79
|
+
export const todoQueries = {
|
|
80
|
+
all: () => queryOptions({
|
|
81
|
+
queryKey: todoKeys.all,
|
|
82
|
+
queryFn: fetchAllTodos,
|
|
83
|
+
}),
|
|
84
|
+
detail: (id: number) => queryOptions({
|
|
85
|
+
queryKey: todoKeys.detail(id),
|
|
86
|
+
queryFn: () => fetchTodo(id),
|
|
87
|
+
staleTime: 5 * 60 * 1000,
|
|
88
|
+
}),
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Usage
|
|
92
|
+
const { data } = useQuery(todoQueries.detail(5))
|
|
93
|
+
await queryClient.prefetchQuery(todoQueries.detail(5))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Context
|
|
97
|
+
|
|
98
|
+
- Essential for applications with 10+ different query types
|
|
99
|
+
- Enables IDE autocomplete and typo prevention
|
|
100
|
+
- Makes invalidation patterns discoverable
|
|
101
|
+
- Pairs well with `queryOptions` for full type inference
|
|
102
|
+
- Consider the `@lukemorales/query-key-factory` package for standardized implementation
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# qk-hierarchical-organization: Organize Keys Hierarchically
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
Structure query keys from general to specific: entity type first, then ID, then modifiers/filters. This enables efficient invalidation at any level of specificity and creates predictable cache organization.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Flat, inconsistent key structures
|
|
13
|
+
const { data: todos } = useQuery({
|
|
14
|
+
queryKey: ['all-todos-list'],
|
|
15
|
+
queryFn: fetchTodos,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const { data: todo } = useQuery({
|
|
19
|
+
queryKey: ['single-todo-5'],
|
|
20
|
+
queryFn: () => fetchTodo(5),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const { data: comments } = useQuery({
|
|
24
|
+
queryKey: ['todo-5-comments'],
|
|
25
|
+
queryFn: () => fetchTodoComments(5),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// Can't easily invalidate all todo-related queries
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Good Example
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
// Hierarchical: entity → id → sub-resource → filters
|
|
35
|
+
const { data: todos } = useQuery({
|
|
36
|
+
queryKey: ['todos'],
|
|
37
|
+
queryFn: fetchTodos,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const { data: todo } = useQuery({
|
|
41
|
+
queryKey: ['todos', 5],
|
|
42
|
+
queryFn: () => fetchTodo(5),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const { data: comments } = useQuery({
|
|
46
|
+
queryKey: ['todos', 5, 'comments'],
|
|
47
|
+
queryFn: () => fetchTodoComments(5),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const { data: filteredTodos } = useQuery({
|
|
51
|
+
queryKey: ['todos', { status: 'done', page: 1 }],
|
|
52
|
+
queryFn: () => fetchTodos({ status: 'done', page: 1 }),
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// Now we can invalidate at any level:
|
|
56
|
+
queryClient.invalidateQueries({ queryKey: ['todos'] }) // All todos
|
|
57
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 5] }) // Todo 5 and its sub-resources
|
|
58
|
+
queryClient.invalidateQueries({ queryKey: ['todos', 5, 'comments'] }) // Just comments
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Recommended Hierarchy Pattern
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
['entity'] // List
|
|
65
|
+
['entity', id] // Single item
|
|
66
|
+
['entity', id, 'sub-resource'] // Related data
|
|
67
|
+
['entity', { filters }] // Filtered list
|
|
68
|
+
['entity', id, 'sub-resource', { filters }] // Filtered sub-resource
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Context
|
|
72
|
+
|
|
73
|
+
- Essential for applications with related data
|
|
74
|
+
- Enables efficient cache management
|
|
75
|
+
- Works with prefix-based invalidation
|
|
76
|
+
- Consider using query key factories (see `qk-factory-pattern`) for consistency
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# qk-include-dependencies: Include All Variables the Query Depends On
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
If your query function depends on a variable, that variable must be included in the query key. This ensures independent caching per variable combination and automatic refetching when dependencies change. Missing dependencies cause stale data bugs and cache collisions.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
function UserPosts({ userId }: { userId: string }) {
|
|
13
|
+
// Missing userId in query key - all users share the same cache!
|
|
14
|
+
const { data } = useQuery({
|
|
15
|
+
queryKey: ['posts'],
|
|
16
|
+
queryFn: () => fetchPostsByUser(userId),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
return <PostList posts={data} />
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function FilteredTodos({ status, page }: { status: string; page: number }) {
|
|
23
|
+
// Missing filter parameters - won't refetch when filters change
|
|
24
|
+
const { data } = useQuery({
|
|
25
|
+
queryKey: ['todos'],
|
|
26
|
+
queryFn: () => fetchTodos({ status, page }),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return <TodoList todos={data} />
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Good Example
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
function UserPosts({ userId }: { userId: string }) {
|
|
37
|
+
// userId included - each user has their own cache entry
|
|
38
|
+
const { data } = useQuery({
|
|
39
|
+
queryKey: ['posts', userId],
|
|
40
|
+
queryFn: () => fetchPostsByUser(userId),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return <PostList posts={data} />
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function FilteredTodos({ status, page }: { status: string; page: number }) {
|
|
47
|
+
// All dependencies included - refetches when any change
|
|
48
|
+
const { data } = useQuery({
|
|
49
|
+
queryKey: ['todos', { status, page }],
|
|
50
|
+
queryFn: () => fetchTodos({ status, page }),
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return <TodoList todos={data} />
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Context
|
|
58
|
+
|
|
59
|
+
- This is arguably the most important query key rule
|
|
60
|
+
- Applies whenever query function uses external variables
|
|
61
|
+
- Prevents subtle bugs where different contexts share cached data
|
|
62
|
+
- Works in conjunction with staleTime - even with long staleTime, changing keys triggers new fetches
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# qk-serializable: Ensure All Key Parts Are JSON-Serializable
|
|
2
|
+
|
|
3
|
+
## Priority: CRITICAL
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
Query keys are hashed using JSON serialization for cache lookups. Non-serializable values (functions, class instances, symbols, circular references) break caching and cause unexpected behavior. All parts of your query key must be JSON-serializable.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Functions are not serializable
|
|
13
|
+
const { data } = useQuery({
|
|
14
|
+
queryKey: ['todos', () => 'active'], // Wrong: function in key
|
|
15
|
+
queryFn: fetchTodos,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
// Class instances lose their prototype
|
|
19
|
+
class Filter {
|
|
20
|
+
constructor(public status: string) {}
|
|
21
|
+
isActive() { return this.status === 'active' }
|
|
22
|
+
}
|
|
23
|
+
const filter = new Filter('active')
|
|
24
|
+
const { data: todos } = useQuery({
|
|
25
|
+
queryKey: ['todos', filter], // Wrong: class instance
|
|
26
|
+
queryFn: () => fetchTodos(filter),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Dates are technically serializable but become strings
|
|
30
|
+
const { data: events } = useQuery({
|
|
31
|
+
queryKey: ['events', new Date()], // Problematic: new Date() each render
|
|
32
|
+
queryFn: () => fetchEvents(date),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Symbols are not serializable
|
|
36
|
+
const { data: settings } = useQuery({
|
|
37
|
+
queryKey: ['settings', Symbol('user')], // Wrong: symbol
|
|
38
|
+
queryFn: fetchSettings,
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Good Example
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
// Use primitive values and plain objects
|
|
46
|
+
const { data } = useQuery({
|
|
47
|
+
queryKey: ['todos', 'active'],
|
|
48
|
+
queryFn: fetchTodos,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Plain objects are fine
|
|
52
|
+
const filters = { status: 'active', priority: 'high' }
|
|
53
|
+
const { data: todos } = useQuery({
|
|
54
|
+
queryKey: ['todos', filters],
|
|
55
|
+
queryFn: () => fetchTodos(filters),
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// For dates, use stable string representations
|
|
59
|
+
const dateKey = date.toISOString().split('T')[0] // '2024-01-15'
|
|
60
|
+
const { data: events } = useQuery({
|
|
61
|
+
queryKey: ['events', dateKey],
|
|
62
|
+
queryFn: () => fetchEvents(date),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// Arrays of primitives work correctly
|
|
66
|
+
const { data: users } = useQuery({
|
|
67
|
+
queryKey: ['users', { ids: [1, 2, 3] }],
|
|
68
|
+
queryFn: () => fetchUsers([1, 2, 3]),
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Serializable Types
|
|
73
|
+
|
|
74
|
+
**Safe to use:**
|
|
75
|
+
- Strings, numbers, booleans, null
|
|
76
|
+
- Plain objects (no prototype methods)
|
|
77
|
+
- Arrays of serializable values
|
|
78
|
+
- undefined (stripped but handled)
|
|
79
|
+
|
|
80
|
+
**Avoid:**
|
|
81
|
+
- Functions
|
|
82
|
+
- Class instances
|
|
83
|
+
- Symbols
|
|
84
|
+
- Date objects (use ISO strings instead)
|
|
85
|
+
- Map/Set (use arrays/objects instead)
|
|
86
|
+
- Circular references
|
|
87
|
+
|
|
88
|
+
## Context
|
|
89
|
+
|
|
90
|
+
- TanStack Query uses deterministic JSON hashing
|
|
91
|
+
- Object property order doesn't matter: `{ a: 1, b: 2 }` equals `{ b: 2, a: 1 }`
|
|
92
|
+
- Keys with `undefined` properties are normalized: `{ a: 1, b: undefined }` equals `{ a: 1 }`
|
|
93
|
+
- Test serialization: `JSON.stringify(queryKey)` should work without errors
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# query-cancellation: Implement Query Cancellation Properly
|
|
2
|
+
|
|
3
|
+
## Priority: MEDIUM
|
|
4
|
+
|
|
5
|
+
## Explanation
|
|
6
|
+
|
|
7
|
+
TanStack Query provides an `AbortSignal` to cancel in-flight requests when queries become stale or components unmount. Pass this signal to your fetch calls to prevent memory leaks and wasted bandwidth.
|
|
8
|
+
|
|
9
|
+
## Bad Example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// Not using abort signal - requests complete even when unnecessary
|
|
13
|
+
const { data } = useQuery({
|
|
14
|
+
queryKey: ['search', searchTerm],
|
|
15
|
+
queryFn: async () => {
|
|
16
|
+
// User types fast: "a", "ab", "abc"
|
|
17
|
+
// Three requests fire, all complete, wasting bandwidth
|
|
18
|
+
const response = await fetch(`/api/search?q=${searchTerm}`)
|
|
19
|
+
return response.json()
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
// Component unmounts but request keeps running
|
|
24
|
+
function UserProfile({ userId }: { userId: string }) {
|
|
25
|
+
const { data } = useQuery({
|
|
26
|
+
queryKey: ['user', userId],
|
|
27
|
+
queryFn: async () => {
|
|
28
|
+
const response = await fetch(`/api/users/${userId}`)
|
|
29
|
+
return response.json() // Completes even if user navigated away
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Good Example: Using AbortSignal with Fetch
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
const { data } = useQuery({
|
|
39
|
+
queryKey: ['search', searchTerm],
|
|
40
|
+
queryFn: async ({ signal }) => {
|
|
41
|
+
const response = await fetch(`/api/search?q=${searchTerm}`, {
|
|
42
|
+
signal, // Pass abort signal to fetch
|
|
43
|
+
})
|
|
44
|
+
return response.json()
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// Now when user types "a", "ab", "abc" quickly:
|
|
49
|
+
// - "a" request is cancelled when "ab" starts
|
|
50
|
+
// - "ab" request is cancelled when "abc" starts
|
|
51
|
+
// - Only "abc" completes
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Good Example: With Axios
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import axios from 'axios'
|
|
58
|
+
|
|
59
|
+
const { data } = useQuery({
|
|
60
|
+
queryKey: ['users', userId],
|
|
61
|
+
queryFn: async ({ signal }) => {
|
|
62
|
+
const response = await axios.get(`/api/users/${userId}`, {
|
|
63
|
+
signal, // Axios supports AbortSignal
|
|
64
|
+
})
|
|
65
|
+
return response.data
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Good Example: Manual Cancellation
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
function SearchResults() {
|
|
74
|
+
const queryClient = useQueryClient()
|
|
75
|
+
const [searchTerm, setSearchTerm] = useState('')
|
|
76
|
+
|
|
77
|
+
const { data } = useQuery({
|
|
78
|
+
queryKey: ['search', searchTerm],
|
|
79
|
+
queryFn: async ({ signal }) => {
|
|
80
|
+
const response = await fetch(`/api/search?q=${searchTerm}`, { signal })
|
|
81
|
+
return response.json()
|
|
82
|
+
},
|
|
83
|
+
enabled: searchTerm.length > 0,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// Cancel all search queries manually
|
|
87
|
+
const handleClear = () => {
|
|
88
|
+
queryClient.cancelQueries({ queryKey: ['search'] })
|
|
89
|
+
setSearchTerm('')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div>
|
|
94
|
+
<input
|
|
95
|
+
value={searchTerm}
|
|
96
|
+
onChange={(e) => setSearchTerm(e.target.value)}
|
|
97
|
+
/>
|
|
98
|
+
<button onClick={handleClear}>Clear</button>
|
|
99
|
+
<Results data={data} />
|
|
100
|
+
</div>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Good Example: In Mutations (Before Optimistic Update)
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
const updateTodo = useMutation({
|
|
109
|
+
mutationFn: (todo: Todo) => api.updateTodo(todo),
|
|
110
|
+
onMutate: async (newTodo) => {
|
|
111
|
+
// Cancel outgoing queries to prevent overwriting optimistic update
|
|
112
|
+
await queryClient.cancelQueries({ queryKey: ['todos'] })
|
|
113
|
+
await queryClient.cancelQueries({ queryKey: ['todos', newTodo.id] })
|
|
114
|
+
|
|
115
|
+
// Proceed with optimistic update...
|
|
116
|
+
const previousTodos = queryClient.getQueryData(['todos'])
|
|
117
|
+
queryClient.setQueryData(['todos'], (old) => /* ... */)
|
|
118
|
+
|
|
119
|
+
return { previousTodos }
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Good Example: Custom Cancellable Promise
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
// For non-fetch APIs that need custom cancellation
|
|
128
|
+
const { data } = useQuery({
|
|
129
|
+
queryKey: ['expensive-computation', params],
|
|
130
|
+
queryFn: ({ signal }) => {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
// Check if already cancelled
|
|
133
|
+
if (signal.aborted) {
|
|
134
|
+
reject(new DOMException('Aborted', 'AbortError'))
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const worker = new Worker('computation.js')
|
|
139
|
+
worker.postMessage(params)
|
|
140
|
+
|
|
141
|
+
worker.onmessage = (e) => resolve(e.data)
|
|
142
|
+
worker.onerror = (e) => reject(e)
|
|
143
|
+
|
|
144
|
+
// Listen for cancellation
|
|
145
|
+
signal.addEventListener('abort', () => {
|
|
146
|
+
worker.terminate()
|
|
147
|
+
reject(new DOMException('Aborted', 'AbortError'))
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## When Queries Are Cancelled
|
|
155
|
+
|
|
156
|
+
| Scenario | Cancelled? |
|
|
157
|
+
|----------|------------|
|
|
158
|
+
| Query key changes | Yes |
|
|
159
|
+
| Component unmounts | Yes |
|
|
160
|
+
| `queryClient.cancelQueries()` called | Yes |
|
|
161
|
+
| Refetch triggered | Previous request cancelled |
|
|
162
|
+
| `enabled` becomes false | Yes |
|
|
163
|
+
|
|
164
|
+
## Context
|
|
165
|
+
|
|
166
|
+
- Always pass `signal` to fetch/axios for automatic cancellation
|
|
167
|
+
- Cancelled queries don't trigger `onError` - they're silently dropped
|
|
168
|
+
- Use `queryClient.cancelQueries()` before optimistic updates
|
|
169
|
+
- AbortError is thrown when cancelled - handle if needed
|
|
170
|
+
- Cancellation prevents wasted bandwidth and race conditions
|
|
171
|
+
- Essential for search-as-you-type and fast navigation patterns
|