Repository: ridafkih/keeper.sh Branch: main Commit: 52256a7abf93 Files: 913 Total size: 8.8 MB Directory structure: gitextract_47nb8t9x/ ├── .claude/ │ ├── settings.json │ └── skills/ │ └── react-best-practices/ │ ├── AGENTS.md │ ├── README.md │ ├── SKILL.md │ ├── metadata.json │ └── rules/ │ ├── _sections.md │ ├── _template.md │ ├── advanced-event-handler-refs.md │ ├── advanced-use-latest.md │ ├── async-api-routes.md │ ├── async-defer-await.md │ ├── async-dependencies.md │ ├── async-parallel.md │ ├── async-suspense-boundaries.md │ ├── bundle-barrel-imports.md │ ├── bundle-conditional.md │ ├── bundle-defer-third-party.md │ ├── bundle-dynamic-imports.md │ ├── bundle-preload.md │ ├── client-event-listeners.md │ ├── client-swr-dedup.md │ ├── js-batch-dom-css.md │ ├── js-cache-function-results.md │ ├── js-cache-property-access.md │ ├── js-cache-storage.md │ ├── js-combine-iterations.md │ ├── js-early-exit.md │ ├── js-hoist-regexp.md │ ├── js-index-maps.md │ ├── js-length-check-first.md │ ├── js-min-max-loop.md │ ├── js-set-map-lookups.md │ ├── js-tosorted-immutable.md │ ├── rendering-activity.md │ ├── rendering-animate-svg-wrapper.md │ ├── rendering-conditional-render.md │ ├── rendering-content-visibility.md │ ├── rendering-hoist-jsx.md │ ├── rendering-hydration-no-flicker.md │ ├── rendering-svg-precision.md │ ├── rerender-defer-reads.md │ ├── rerender-dependencies.md │ ├── rerender-derived-state.md │ ├── rerender-functional-setstate.md │ ├── rerender-lazy-state-init.md │ ├── rerender-memo.md │ ├── rerender-transitions.md │ ├── server-after-nonblocking.md │ ├── server-cache-lru.md │ ├── server-cache-react.md │ ├── server-parallel-fetching.md │ └── server-serialization.md ├── .dockerignore ├── .github/ │ ├── FUNDING.yml │ └── workflows/ │ ├── checks.yml │ └── docker-publish.yml ├── .gitignore ├── .oxlintrc.json ├── Caddyfile ├── LICENSE ├── NOTICE ├── README.md ├── applications/ │ └── web/ │ ├── .eslintrc.cjs │ ├── .gitignore │ ├── Dockerfile │ ├── README.md │ ├── entrypoint.sh │ ├── eslint.config.js │ ├── index.html │ ├── package.json │ ├── plugins/ │ │ ├── blog.ts │ │ └── sitemap.ts │ ├── public/ │ │ ├── llms-full.txt │ │ ├── llms.txt │ │ ├── robots.txt │ │ └── site.webmanifest │ ├── scripts/ │ │ ├── build.ts │ │ └── start.ts │ ├── src/ │ │ ├── components/ │ │ │ ├── analytics-scripts.tsx │ │ │ ├── cookie-consent.tsx │ │ │ └── ui/ │ │ │ ├── composites/ │ │ │ │ └── navigation-menu/ │ │ │ │ ├── navigation-menu-editable.tsx │ │ │ │ ├── navigation-menu-items.tsx │ │ │ │ ├── navigation-menu-popover.tsx │ │ │ │ ├── navigation-menu.contexts.ts │ │ │ │ └── navigation-menu.styles.ts │ │ │ ├── primitives/ │ │ │ │ ├── animated-reveal.tsx │ │ │ │ ├── back-button.tsx │ │ │ │ ├── button.tsx │ │ │ │ ├── checkbox.tsx │ │ │ │ ├── collapsible.tsx │ │ │ │ ├── dashboard-heading.tsx │ │ │ │ ├── delete-confirmation.tsx │ │ │ │ ├── divider.tsx │ │ │ │ ├── error-state.tsx │ │ │ │ ├── fade-in.tsx │ │ │ │ ├── github-star-button.tsx │ │ │ │ ├── heading.tsx │ │ │ │ ├── input.tsx │ │ │ │ ├── list.tsx │ │ │ │ ├── markdown-component-map.ts │ │ │ │ ├── markdown-components.tsx │ │ │ │ ├── modal.tsx │ │ │ │ ├── pagination.tsx │ │ │ │ ├── provider-icon-stack.tsx │ │ │ │ ├── provider-icon.tsx │ │ │ │ ├── shimmer-text.tsx │ │ │ │ ├── staggered-backdrop-blur.tsx │ │ │ │ ├── template-text.tsx │ │ │ │ ├── text-link.tsx │ │ │ │ ├── text.tsx │ │ │ │ ├── tooltip.tsx │ │ │ │ └── upgrade-hint.tsx │ │ │ └── shells/ │ │ │ ├── layout.tsx │ │ │ ├── route-shell.tsx │ │ │ └── session-slot.tsx │ │ ├── config/ │ │ │ ├── commercial.ts │ │ │ ├── gdpr.ts │ │ │ └── plans.ts │ │ ├── content/ │ │ │ └── blog/ │ │ │ └── introducing-keeper-blog.mdx │ │ ├── features/ │ │ │ ├── auth/ │ │ │ │ └── components/ │ │ │ │ ├── auth-form.tsx │ │ │ │ ├── auth-switch-prompt.tsx │ │ │ │ ├── caldav-connect-form.tsx │ │ │ │ ├── caldav-connect-page.tsx │ │ │ │ ├── ics-connect-form.tsx │ │ │ │ └── oauth-preamble.tsx │ │ │ ├── blog/ │ │ │ │ └── components/ │ │ │ │ └── blog-post-cta.tsx │ │ │ ├── dashboard/ │ │ │ │ └── components/ │ │ │ │ ├── event-graph.tsx │ │ │ │ ├── metadata-row.tsx │ │ │ │ ├── sync-status-helpers.ts │ │ │ │ ├── sync-status.tsx │ │ │ │ └── upgrade-card.tsx │ │ │ └── marketing/ │ │ │ ├── components/ │ │ │ │ ├── marketing-cta.tsx │ │ │ │ ├── marketing-faq.tsx │ │ │ │ ├── marketing-feature-bento.tsx │ │ │ │ ├── marketing-footer.tsx │ │ │ │ ├── marketing-header.tsx │ │ │ │ ├── marketing-how-it-works.tsx │ │ │ │ ├── marketing-illustration-calendar.tsx │ │ │ │ └── marketing-pricing-section.tsx │ │ │ └── contributors.json │ │ ├── generated/ │ │ │ └── tanstack/ │ │ │ └── route-tree.generated.ts │ │ ├── hooks/ │ │ │ ├── use-animated-swr.ts │ │ │ ├── use-api-tokens.ts │ │ │ ├── use-entitlements.ts │ │ │ ├── use-events.ts │ │ │ ├── use-has-password.ts │ │ │ ├── use-passkeys.ts │ │ │ ├── use-session.ts │ │ │ ├── use-start-of-today.ts │ │ │ └── use-subscription.ts │ │ ├── illustrations/ │ │ │ ├── how-it-works-configure.tsx │ │ │ ├── how-it-works-connect.tsx │ │ │ ├── how-it-works-sync.tsx │ │ │ ├── marketing-illustration-contributors.tsx │ │ │ ├── marketing-illustration-providers.tsx │ │ │ ├── marketing-illustration-setup.tsx │ │ │ └── marketing-illustration-sync.tsx │ │ ├── index.css │ │ ├── index.d.ts │ │ ├── lib/ │ │ │ ├── analytics.ts │ │ │ ├── auth-capabilities.ts │ │ │ ├── auth-client.ts │ │ │ ├── auth.ts │ │ │ ├── blog-posts.ts │ │ │ ├── fetcher.ts │ │ │ ├── mcp-auth-flow.ts │ │ │ ├── motion-features.ts │ │ │ ├── page-metadata.ts │ │ │ ├── pluralize.ts │ │ │ ├── providers.ts │ │ │ ├── route-access-guards.ts │ │ │ ├── router-context.ts │ │ │ ├── runtime-config.ts │ │ │ ├── seo.ts │ │ │ ├── serialized-mutate.ts │ │ │ ├── session-cookie.ts │ │ │ ├── swr.ts │ │ │ └── time.ts │ │ ├── main.tsx │ │ ├── providers/ │ │ │ ├── sync-provider-logic.ts │ │ │ └── sync-provider.tsx │ │ ├── routeTree.gen.ts │ │ ├── router.ts │ │ ├── routes/ │ │ │ ├── (auth)/ │ │ │ │ ├── forgot-password.tsx │ │ │ │ ├── login.tsx │ │ │ │ ├── register.tsx │ │ │ │ ├── reset-password.tsx │ │ │ │ ├── route.tsx │ │ │ │ ├── verify-authentication.tsx │ │ │ │ └── verify-email.tsx │ │ │ ├── (dashboard)/ │ │ │ │ ├── dashboard/ │ │ │ │ │ ├── accounts/ │ │ │ │ │ │ ├── $accountId.$calendarId.tsx │ │ │ │ │ │ ├── $accountId.index.tsx │ │ │ │ │ │ ├── $accountId.setup.tsx │ │ │ │ │ │ └── route.tsx │ │ │ │ │ ├── connect/ │ │ │ │ │ │ ├── index.tsx │ │ │ │ │ │ └── route.tsx │ │ │ │ │ ├── events/ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── feedback.tsx │ │ │ │ │ ├── ical.tsx │ │ │ │ │ ├── index.tsx │ │ │ │ │ ├── integrations/ │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── report.tsx │ │ │ │ │ ├── settings/ │ │ │ │ │ │ ├── api-tokens.tsx │ │ │ │ │ │ ├── change-password.tsx │ │ │ │ │ │ ├── index.tsx │ │ │ │ │ │ ├── passkeys.tsx │ │ │ │ │ │ └── route.tsx │ │ │ │ │ └── upgrade/ │ │ │ │ │ └── index.tsx │ │ │ │ └── route.tsx │ │ │ ├── (marketing)/ │ │ │ │ ├── blog/ │ │ │ │ │ ├── $slug.tsx │ │ │ │ │ ├── index.tsx │ │ │ │ │ └── route.tsx │ │ │ │ ├── index.tsx │ │ │ │ ├── privacy.tsx │ │ │ │ ├── route.tsx │ │ │ │ └── terms.tsx │ │ │ ├── (oauth)/ │ │ │ │ ├── auth/ │ │ │ │ │ ├── google.tsx │ │ │ │ │ ├── outlook.tsx │ │ │ │ │ └── route.tsx │ │ │ │ ├── dashboard/ │ │ │ │ │ ├── connect/ │ │ │ │ │ │ ├── apple.tsx │ │ │ │ │ │ ├── caldav.tsx │ │ │ │ │ │ ├── fastmail.tsx │ │ │ │ │ │ ├── google.tsx │ │ │ │ │ │ ├── ical-link.tsx │ │ │ │ │ │ ├── ics-file.tsx │ │ │ │ │ │ ├── microsoft.tsx │ │ │ │ │ │ ├── outlook.tsx │ │ │ │ │ │ └── route.tsx │ │ │ │ │ └── route.tsx │ │ │ │ ├── oauth/ │ │ │ │ │ └── consent.tsx │ │ │ │ └── route.tsx │ │ │ └── __root.tsx │ │ ├── server/ │ │ │ ├── cache/ │ │ │ │ └── stale-cache.ts │ │ │ ├── compression.ts │ │ │ ├── config.ts │ │ │ ├── github-stars.ts │ │ │ ├── http-handler.ts │ │ │ ├── index.ts │ │ │ ├── internal-routes.ts │ │ │ ├── logging.ts │ │ │ ├── migration-check.ts │ │ │ ├── paths.ts │ │ │ ├── proxy/ │ │ │ │ ├── http.ts │ │ │ │ └── websocket.ts │ │ │ ├── runtime.ts │ │ │ ├── types.ts │ │ │ └── vite-assets.ts │ │ ├── server.tsx │ │ ├── state/ │ │ │ ├── auth-form.ts │ │ │ ├── calendar-detail.ts │ │ │ ├── calendar-emphasized.ts │ │ │ ├── destination-ids.ts │ │ │ ├── event-graph-hover.ts │ │ │ ├── ical-feed-settings.ts │ │ │ ├── ical-sources.ts │ │ │ ├── popover-overlay.ts │ │ │ └── sync.ts │ │ ├── types/ │ │ │ └── api.ts │ │ ├── utils/ │ │ │ ├── calendars.ts │ │ │ ├── checkout.ts │ │ │ ├── cn.ts │ │ │ ├── collections.ts │ │ │ ├── errors.ts │ │ │ └── templates.ts │ │ └── vite-env.d.ts │ ├── tests/ │ │ ├── features/ │ │ │ ├── auth/ │ │ │ │ └── components/ │ │ │ │ └── auth-form.test.tsx │ │ │ └── dashboard/ │ │ │ └── components/ │ │ │ └── sync-status-helpers.test.ts │ │ ├── hooks/ │ │ │ └── use-entitlements.test.ts │ │ ├── lib/ │ │ │ ├── auth-capabilities.test.ts │ │ │ ├── auth.test.ts │ │ │ ├── mcp-auth-flow.test.ts │ │ │ ├── route-access-guards.test.ts │ │ │ ├── runtime-config.test.ts │ │ │ └── serialized-mutate.test.ts │ │ ├── providers/ │ │ │ └── sync-provider-logic.test.ts │ │ ├── server/ │ │ │ └── internal-routes.test.ts │ │ └── state/ │ │ └── sync.test.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ ├── vite.config.ts │ └── vitest.config.ts ├── bunfig.toml ├── compose.yaml ├── deploy/ │ ├── Caddyfile │ └── compose.yaml ├── docker/ │ ├── caddy/ │ │ └── Dockerfile │ ├── services/ │ │ ├── Dockerfile │ │ └── rootfs/ │ │ └── etc/ │ │ └── s6-overlay/ │ │ ├── s6-rc.d/ │ │ │ ├── api/ │ │ │ │ ├── dependencies.d/ │ │ │ │ │ └── init-db │ │ │ │ ├── run │ │ │ │ └── type │ │ │ ├── cron/ │ │ │ │ ├── dependencies.d/ │ │ │ │ │ └── init-db │ │ │ │ ├── run │ │ │ │ └── type │ │ │ ├── init-db/ │ │ │ │ ├── type │ │ │ │ └── up │ │ │ ├── user/ │ │ │ │ ├── contents.d/ │ │ │ │ │ ├── api │ │ │ │ │ ├── cron │ │ │ │ │ ├── init-db │ │ │ │ │ ├── web │ │ │ │ │ └── worker │ │ │ │ └── type │ │ │ ├── web/ │ │ │ │ ├── dependencies.d/ │ │ │ │ │ └── api │ │ │ │ ├── run │ │ │ │ └── type │ │ │ └── worker/ │ │ │ ├── dependencies.d/ │ │ │ │ └── init-db │ │ │ ├── run │ │ │ └── type │ │ └── scripts/ │ │ └── init-db │ └── standalone/ │ ├── Dockerfile │ └── rootfs/ │ └── etc/ │ ├── caddy/ │ │ └── Caddyfile │ └── s6-overlay/ │ ├── s6-rc.d/ │ │ ├── api/ │ │ │ ├── dependencies.d/ │ │ │ │ ├── init-db │ │ │ │ └── redis │ │ │ ├── run │ │ │ └── type │ │ ├── caddy/ │ │ │ ├── dependencies.d/ │ │ │ │ └── web │ │ │ ├── run │ │ │ └── type │ │ ├── cron/ │ │ │ ├── dependencies.d/ │ │ │ │ ├── init-db │ │ │ │ └── redis │ │ │ ├── run │ │ │ └── type │ │ ├── init-db/ │ │ │ ├── dependencies.d/ │ │ │ │ └── postgres │ │ │ ├── type │ │ │ └── up │ │ ├── postgres/ │ │ │ ├── dependencies.d/ │ │ │ │ └── base │ │ │ ├── run │ │ │ └── type │ │ ├── redis/ │ │ │ ├── dependencies.d/ │ │ │ │ └── base │ │ │ ├── run │ │ │ └── type │ │ ├── user/ │ │ │ ├── contents.d/ │ │ │ │ ├── api │ │ │ │ ├── caddy │ │ │ │ ├── cron │ │ │ │ ├── init-db │ │ │ │ ├── postgres │ │ │ │ ├── redis │ │ │ │ ├── web │ │ │ │ └── worker │ │ │ └── type │ │ ├── web/ │ │ │ ├── dependencies.d/ │ │ │ │ └── api │ │ │ ├── run │ │ │ └── type │ │ └── worker/ │ │ ├── dependencies.d/ │ │ │ ├── init-db │ │ │ └── redis │ │ ├── run │ │ └── type │ └── scripts/ │ └── init-db ├── knip.json ├── lefthook.yml ├── package.json ├── packages/ │ ├── auth/ │ │ ├── package.json │ │ ├── src/ │ │ │ ├── capabilities.ts │ │ │ ├── index.ts │ │ │ ├── mcp-config.ts │ │ │ ├── plugins/ │ │ │ │ └── username-only/ │ │ │ │ ├── endpoints/ │ │ │ │ │ ├── sign-in.ts │ │ │ │ │ └── sign-up.ts │ │ │ │ ├── index.ts │ │ │ │ ├── types.ts │ │ │ │ └── utils/ │ │ │ │ ├── config.ts │ │ │ │ └── schema.ts │ │ │ ├── polar-customer-delete.ts │ │ │ └── runtime-environment.ts │ │ ├── tests/ │ │ │ ├── capabilities.test.ts │ │ │ ├── mcp-config.test.ts │ │ │ └── polar-customer-delete.test.ts │ │ ├── tsconfig.json │ │ └── vitest.config.ts │ ├── broadcast/ │ │ ├── package.json │ │ ├── src/ │ │ │ ├── index.ts │ │ │ ├── state.ts │ │ │ └── types.ts │ │ └── tsconfig.json │ ├── calendar/ │ │ ├── package.json │ │ ├── src/ │ │ │ ├── core/ │ │ │ │ ├── events/ │ │ │ │ │ ├── all-day.ts │ │ │ │ │ ├── content-hash.ts │ │ │ │ │ ├── events.ts │ │ │ │ │ ├── identity.ts │ │ │ │ │ ├── mappings.ts │ │ │ │ │ └── recurrence.ts │ │ │ │ ├── oauth/ │ │ │ │ │ ├── accounts.ts │ │ │ │ │ ├── config.ts │ │ │ │ │ ├── coordinated-refresher.ts │ │ │ │ │ ├── create-source-provider.ts │ │ │ │ │ ├── ensure-valid-token.ts │ │ │ │ │ ├── error-classification.ts │ │ │ │ │ ├── google.ts │ │ │ │ │ ├── microsoft.ts │ │ │ │ │ ├── providers.ts │ │ │ │ │ ├── refresh-coordinator.ts │ │ │ │ │ ├── source-provider.ts │ │ │ │ │ ├── state.ts │ │ │ │ │ ├── sync-token.ts │ │ │ │ │ ├── sync-window.ts │ │ │ │ │ └── token-provider.ts │ │ │ │ ├── source/ │ │ │ │ │ ├── event-diff.ts │ │ │ │ │ ├── sync-diagnostics.ts │ │ │ │ │ └── write-event-states.ts │ │ │ │ ├── sync/ │ │ │ │ │ ├── aggregate-runtime.ts │ │ │ │ │ ├── aggregate-tracker.ts │ │ │ │ │ ├── operations.ts │ │ │ │ │ └── types.ts │ │ │ │ ├── sync-engine/ │ │ │ │ │ ├── flush.ts │ │ │ │ │ ├── generation.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── ingest.ts │ │ │ │ │ └── types.ts │ │ │ │ ├── types.ts │ │ │ │ └── utils/ │ │ │ │ ├── concurrency.ts │ │ │ │ ├── error.ts │ │ │ │ ├── rate-limiter.ts │ │ │ │ └── redis-rate-limiter.ts │ │ │ ├── ics/ │ │ │ │ ├── index.ts │ │ │ │ ├── types.ts │ │ │ │ └── utils/ │ │ │ │ ├── create-snapshot.ts │ │ │ │ ├── diff-events.ts │ │ │ │ ├── fetch-adapter.ts │ │ │ │ ├── normalize-timezone.ts │ │ │ │ ├── parse-ics-calendar.ts │ │ │ │ ├── parse-ics-events.ts │ │ │ │ ├── pull-remote-calendar.ts │ │ │ │ └── types.ts │ │ │ ├── index.ts │ │ │ ├── providers/ │ │ │ │ ├── caldav/ │ │ │ │ │ ├── destination/ │ │ │ │ │ │ └── provider.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── shared/ │ │ │ │ │ │ ├── client.ts │ │ │ │ │ │ ├── digest-fetch.ts │ │ │ │ │ │ ├── ics.ts │ │ │ │ │ │ └── sync-window.ts │ │ │ │ │ ├── source/ │ │ │ │ │ │ ├── auth-error-classification.ts │ │ │ │ │ │ ├── fetch-adapter.ts │ │ │ │ │ │ ├── provider.ts │ │ │ │ │ │ ├── sync-window.ts │ │ │ │ │ │ └── sync.ts │ │ │ │ │ └── types.ts │ │ │ │ ├── fastmail/ │ │ │ │ │ ├── destination/ │ │ │ │ │ │ └── provider.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ └── source/ │ │ │ │ │ └── provider.ts │ │ │ │ ├── google/ │ │ │ │ │ ├── destination/ │ │ │ │ │ │ ├── provider.ts │ │ │ │ │ │ ├── serialize-event.ts │ │ │ │ │ │ └── sync.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── shared/ │ │ │ │ │ │ ├── api.ts │ │ │ │ │ │ ├── backoff.ts │ │ │ │ │ │ ├── batch.ts │ │ │ │ │ │ ├── date-time.ts │ │ │ │ │ │ └── errors.ts │ │ │ │ │ ├── source/ │ │ │ │ │ │ ├── fetch-adapter.ts │ │ │ │ │ │ ├── provider.ts │ │ │ │ │ │ ├── types.ts │ │ │ │ │ │ └── utils/ │ │ │ │ │ │ ├── fetch-events.ts │ │ │ │ │ │ └── list-calendars.ts │ │ │ │ │ └── types.ts │ │ │ │ ├── icloud/ │ │ │ │ │ ├── destination/ │ │ │ │ │ │ └── provider.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ └── source/ │ │ │ │ │ └── provider.ts │ │ │ │ └── outlook/ │ │ │ │ ├── destination/ │ │ │ │ │ ├── provider.ts │ │ │ │ │ ├── serialize-event.ts │ │ │ │ │ └── sync.ts │ │ │ │ ├── index.ts │ │ │ │ ├── shared/ │ │ │ │ │ ├── api.ts │ │ │ │ │ ├── date-time.ts │ │ │ │ │ └── errors.ts │ │ │ │ ├── source/ │ │ │ │ │ ├── fetch-adapter.ts │ │ │ │ │ ├── provider.ts │ │ │ │ │ ├── types.ts │ │ │ │ │ └── utils/ │ │ │ │ │ ├── fetch-events.ts │ │ │ │ │ └── list-calendars.ts │ │ │ │ └── types.ts │ │ │ └── utils/ │ │ │ ├── registry/ │ │ │ │ ├── registry.ts │ │ │ │ └── server.ts │ │ │ └── safe-fetch.ts │ │ ├── tests/ │ │ │ ├── core/ │ │ │ │ ├── events/ │ │ │ │ │ ├── content-hash.test.ts │ │ │ │ │ ├── events.test.ts │ │ │ │ │ ├── identity.test.ts │ │ │ │ │ └── recurrence.test.ts │ │ │ │ ├── oauth/ │ │ │ │ │ ├── ensure-valid-token.test.ts │ │ │ │ │ ├── error-classification.test.ts │ │ │ │ │ ├── google.test.ts │ │ │ │ │ ├── refresh-coordinator.test.ts │ │ │ │ │ ├── sync-token.test.ts │ │ │ │ │ └── sync-window.test.ts │ │ │ │ ├── source/ │ │ │ │ │ ├── event-diff.test.ts │ │ │ │ │ ├── sync-diagnostics.test.ts │ │ │ │ │ └── write-event-states.test.ts │ │ │ │ ├── sync/ │ │ │ │ │ ├── aggregate-runtime.test.ts │ │ │ │ │ ├── aggregate-tracker.test.ts │ │ │ │ │ └── operations.test.ts │ │ │ │ ├── sync-engine/ │ │ │ │ │ ├── index.test.ts │ │ │ │ │ └── ingest.test.ts │ │ │ │ └── utils/ │ │ │ │ └── rate-limiter.test.ts │ │ │ ├── ics/ │ │ │ │ └── utils/ │ │ │ │ ├── diff-events-extended.test.ts │ │ │ │ ├── diff-events.test.ts │ │ │ │ ├── ics-fixtures.test.ts │ │ │ │ ├── normalize-timezone.test.ts │ │ │ │ ├── outlook-windows-timezone.test.ts │ │ │ │ ├── parse-ics-calendar.test.ts │ │ │ │ └── parse-ics-events.test.ts │ │ │ ├── providers/ │ │ │ │ ├── caldav/ │ │ │ │ │ ├── destination/ │ │ │ │ │ │ └── provider.test.ts │ │ │ │ │ ├── shared/ │ │ │ │ │ │ ├── ics-fixtures.test.ts │ │ │ │ │ │ ├── ics.test.ts │ │ │ │ │ │ └── sync-window.test.ts │ │ │ │ │ └── source/ │ │ │ │ │ ├── auth-error-classification.test.ts │ │ │ │ │ ├── fetch-adapter.test.ts │ │ │ │ │ └── sync-window.test.ts │ │ │ │ ├── google/ │ │ │ │ │ ├── destination/ │ │ │ │ │ │ ├── provider.test.ts │ │ │ │ │ │ └── serialize-event.test.ts │ │ │ │ │ ├── shared/ │ │ │ │ │ │ ├── backoff.test.ts │ │ │ │ │ │ ├── batch.test.ts │ │ │ │ │ │ └── errors.test.ts │ │ │ │ │ └── source/ │ │ │ │ │ ├── fetch-adapter.test.ts │ │ │ │ │ ├── provider.test.ts │ │ │ │ │ └── utils/ │ │ │ │ │ └── fetch-events.test.ts │ │ │ │ └── outlook/ │ │ │ │ ├── destination/ │ │ │ │ │ ├── provider.test.ts │ │ │ │ │ └── serialize-event.test.ts │ │ │ │ └── source/ │ │ │ │ ├── fetch-adapter.test.ts │ │ │ │ ├── provider.test.ts │ │ │ │ └── utils/ │ │ │ │ └── fetch-events.test.ts │ │ │ └── utils/ │ │ │ └── safe-fetch.test.ts │ │ ├── tsconfig.json │ │ └── vitest.config.ts │ ├── constants/ │ │ ├── package.json │ │ ├── src/ │ │ │ ├── constants/ │ │ │ │ ├── http.ts │ │ │ │ ├── scopes.ts │ │ │ │ └── time.ts │ │ │ └── index.ts │ │ └── tsconfig.json │ ├── data-schemas/ │ │ ├── package.json │ │ ├── src/ │ │ │ ├── client.ts │ │ │ └── index.ts │ │ └── tsconfig.json │ ├── database/ │ │ ├── drizzle/ │ │ │ ├── 0000_slimy_justice.sql │ │ │ ├── 0001_complete_golden_guardian.sql │ │ │ ├── 0002_striped_queen_noir.sql │ │ │ ├── 0003_nervous_vulcan.sql │ │ │ ├── 0004_strong_midnight.sql │ │ │ ├── 0005_dusty_nomad.sql │ │ │ ├── 0006_curious_orphan.sql │ │ │ ├── 0007_heavy_pretty_boy.sql │ │ │ ├── 0008_vengeful_azazel.sql │ │ │ ├── 0009_daily_thor_girl.sql │ │ │ ├── 0010_heavy_prima.sql │ │ │ ├── 0011_round_gorilla_man.sql │ │ │ ├── 0012_vengeful_thena.sql │ │ │ ├── 0013_parallel_union_jack.sql │ │ │ ├── 0014_modern_talon.sql │ │ │ ├── 0015_unique_impossible_man.sql │ │ │ ├── 0016_salty_nextwave.sql │ │ │ ├── 0017_outstanding_eddie_brock.sql │ │ │ ├── 0018_whole_loa.sql │ │ │ ├── 0019_tearful_doctor_doom.sql │ │ │ ├── 0020_huge_talon.sql │ │ │ ├── 0021_icy_white_queen.sql │ │ │ ├── 0022_lazy_avengers.sql │ │ │ ├── 0023_lyrical_genesis.sql │ │ │ ├── 0024_aberrant_wallop.sql │ │ │ ├── 0025_powerful_sentinels.sql │ │ │ ├── 0026_typical_impossible_man.sql │ │ │ ├── 0027_loose_hydra.sql │ │ │ ├── 0028_lush_sumo.sql │ │ │ ├── 0029_huge_yellow_claw.sql │ │ │ ├── 0030_youthful_speed.sql │ │ │ ├── 0031_glorious_joshua_kane.sql │ │ │ ├── 0032_dapper_patch.sql │ │ │ ├── 0033_square_tomorrow_man.sql │ │ │ ├── 0034_dumb_clanker.sql │ │ │ ├── 0035_known_silk_fever.sql │ │ │ ├── 0036_late_bastion.sql │ │ │ ├── 0037_thankful_machine_man.sql │ │ │ ├── 0038_military_radioactive_man.sql │ │ │ ├── 0039_fat_mad_thinker.sql │ │ │ ├── 0040_sparkling_toad.sql │ │ │ ├── 0041_keen_black_panther.sql │ │ │ ├── 0042_famous_obadiah_stane.sql │ │ │ ├── 0043_smart_demogoblin.sql │ │ │ ├── 0044_crazy_kate_bishop.sql │ │ │ ├── 0045_flippant_paper_doll.sql │ │ │ ├── 0046_rainy_steve_rogers.sql │ │ │ ├── 0047_soft_ravenous.sql │ │ │ ├── 0048_gigantic_kid_colt.sql │ │ │ ├── 0049_handy_sentinels.sql │ │ │ ├── 0050_purple_patch.sql │ │ │ ├── 0051_normal_mentallo.sql │ │ │ ├── 0052_military_trish_tilby.sql │ │ │ ├── 0053_greedy_reptil.sql │ │ │ ├── 0054_nasty_sage.sql │ │ │ ├── 0055_zippy_wolfsbane.sql │ │ │ ├── 0056_ambiguous_unus.sql │ │ │ ├── 0057_requeue_source_backfill.sql │ │ │ ├── 0058_same_robbie_robertson.sql │ │ │ ├── 0059_shocking_stone_men.sql │ │ │ ├── 0060_condemned_imperial_guard.sql │ │ │ ├── 0061_brief_toxin.sql │ │ │ ├── 0062_lame_white_tiger.sql │ │ │ ├── 0063_friendly_black_panther.sql │ │ │ ├── 0064_talented_black_knight.sql │ │ │ ├── 0065_dizzy_zarda.sql │ │ │ ├── 0066_nasty_bushwacker.sql │ │ │ ├── 0067_curvy_mole_man.sql │ │ │ ├── 0068_clumsy_starbolt.sql │ │ │ ├── 0069_amazing_storm.sql │ │ │ └── meta/ │ │ │ ├── 0000_snapshot.json │ │ │ ├── 0001_snapshot.json │ │ │ ├── 0002_snapshot.json │ │ │ ├── 0003_snapshot.json │ │ │ ├── 0004_snapshot.json │ │ │ ├── 0005_snapshot.json │ │ │ ├── 0006_snapshot.json │ │ │ ├── 0007_snapshot.json │ │ │ ├── 0008_snapshot.json │ │ │ ├── 0009_snapshot.json │ │ │ ├── 0010_snapshot.json │ │ │ ├── 0011_snapshot.json │ │ │ ├── 0012_snapshot.json │ │ │ ├── 0013_snapshot.json │ │ │ ├── 0014_snapshot.json │ │ │ ├── 0015_snapshot.json │ │ │ ├── 0016_snapshot.json │ │ │ ├── 0017_snapshot.json │ │ │ ├── 0018_snapshot.json │ │ │ ├── 0019_snapshot.json │ │ │ ├── 0020_snapshot.json │ │ │ ├── 0021_snapshot.json │ │ │ ├── 0022_snapshot.json │ │ │ ├── 0023_snapshot.json │ │ │ ├── 0024_snapshot.json │ │ │ ├── 0025_snapshot.json │ │ │ ├── 0026_snapshot.json │ │ │ ├── 0027_snapshot.json │ │ │ ├── 0028_snapshot.json │ │ │ ├── 0029_snapshot.json │ │ │ ├── 0030_snapshot.json │ │ │ ├── 0031_snapshot.json │ │ │ ├── 0032_snapshot.json │ │ │ ├── 0033_snapshot.json │ │ │ ├── 0034_snapshot.json │ │ │ ├── 0035_snapshot.json │ │ │ ├── 0036_snapshot.json │ │ │ ├── 0037_snapshot.json │ │ │ ├── 0038_snapshot.json │ │ │ ├── 0039_snapshot.json │ │ │ ├── 0040_snapshot.json │ │ │ ├── 0041_snapshot.json │ │ │ ├── 0042_snapshot.json │ │ │ ├── 0043_snapshot.json │ │ │ ├── 0044_snapshot.json │ │ │ ├── 0045_snapshot.json │ │ │ ├── 0046_snapshot.json │ │ │ ├── 0047_snapshot.json │ │ │ ├── 0048_snapshot.json │ │ │ ├── 0049_snapshot.json │ │ │ ├── 0050_snapshot.json │ │ │ ├── 0051_snapshot.json │ │ │ ├── 0052_snapshot.json │ │ │ ├── 0053_snapshot.json │ │ │ ├── 0054_snapshot.json │ │ │ ├── 0055_snapshot.json │ │ │ ├── 0056_snapshot.json │ │ │ ├── 0057_snapshot.json │ │ │ ├── 0058_snapshot.json │ │ │ ├── 0059_snapshot.json │ │ │ ├── 0060_snapshot.json │ │ │ ├── 0061_snapshot.json │ │ │ ├── 0062_snapshot.json │ │ │ ├── 0063_snapshot.json │ │ │ ├── 0064_snapshot.json │ │ │ ├── 0065_snapshot.json │ │ │ ├── 0066_snapshot.json │ │ │ ├── 0067_snapshot.json │ │ │ ├── 0068_snapshot.json │ │ │ ├── 0069_snapshot.json │ │ │ └── _journal.json │ │ ├── drizzle.config.ts │ │ ├── package.json │ │ ├── scripts/ │ │ │ └── migrate.ts │ │ ├── src/ │ │ │ ├── database/ │ │ │ │ ├── auth-schema.ts │ │ │ │ └── schema.ts │ │ │ ├── encryption.ts │ │ │ ├── index.ts │ │ │ └── utils/ │ │ │ └── database.ts │ │ ├── tests/ │ │ │ └── database/ │ │ │ └── auth-schema.test.ts │ │ ├── tsconfig.json │ │ ├── turbo.json │ │ └── vitest.config.ts │ ├── digest-fetch/ │ │ ├── package.json │ │ ├── src/ │ │ │ └── index.ts │ │ └── tsconfig.json │ ├── fixtures/ │ │ ├── ics/ │ │ │ ├── berkeley-ib-seminars.ics │ │ │ ├── calendarlabs-us-holidays.ics │ │ │ ├── google-canada-holidays.ics │ │ │ ├── google-us-holidays.ics │ │ │ ├── govuk-bank-holidays-england-wales.ics │ │ │ ├── hebcal-geoname-3448439.ics │ │ │ ├── meetup-ny-tech.ics │ │ │ ├── meetup-torontojs.ics │ │ │ ├── outlook-exchange-windows-timezones.ics │ │ │ └── stanford-featured-events.ics │ │ ├── package.json │ │ ├── src/ │ │ │ ├── cache.ts │ │ │ ├── index.ts │ │ │ ├── manifest.ts │ │ │ ├── schema.ts │ │ │ └── scripts/ │ │ │ ├── sync-fixtures.ts │ │ │ └── verify-fixtures.ts │ │ └── tsconfig.json │ ├── otelemetry/ │ │ ├── package.json │ │ ├── src/ │ │ │ └── index.ts │ │ └── tsconfig.json │ ├── premium/ │ │ ├── package.json │ │ ├── src/ │ │ │ ├── constants.ts │ │ │ ├── index.ts │ │ │ └── subscription.ts │ │ └── tsconfig.json │ ├── queue/ │ │ ├── package.json │ │ ├── src/ │ │ │ └── index.ts │ │ └── tsconfig.json │ ├── sync/ │ │ ├── package.json │ │ ├── src/ │ │ │ ├── destination-errors.ts │ │ │ ├── index.ts │ │ │ ├── resolve-provider.ts │ │ │ ├── sync-lock.ts │ │ │ └── sync-user.ts │ │ ├── tests/ │ │ │ ├── destination-errors.test.ts │ │ │ └── sync-lock.test.ts │ │ ├── tsconfig.json │ │ └── vitest.config.ts │ └── typescript-config/ │ ├── package.json │ └── tsconfig.json ├── scripts/ │ └── bun-test.ts ├── services/ │ ├── api/ │ │ ├── Dockerfile │ │ ├── entrypoint.sh │ │ ├── package.json │ │ ├── scripts/ │ │ │ └── build.ts │ │ ├── src/ │ │ │ ├── context.ts │ │ │ ├── env.ts │ │ │ ├── handlers/ │ │ │ │ ├── auth-oauth-resource.ts │ │ │ │ ├── auth.ts │ │ │ │ ├── websocket-initial-status.ts │ │ │ │ ├── websocket-payload.ts │ │ │ │ └── websocket.ts │ │ │ ├── index.ts │ │ │ ├── middleware/ │ │ │ │ └── cors.ts │ │ │ ├── mutations/ │ │ │ │ ├── index.ts │ │ │ │ ├── providers/ │ │ │ │ │ ├── caldav.ts │ │ │ │ │ ├── google.ts │ │ │ │ │ └── outlook.ts │ │ │ │ └── resolve-credentials.ts │ │ │ ├── provider-display.ts │ │ │ ├── queries/ │ │ │ │ ├── get-event-count.ts │ │ │ │ ├── get-event.ts │ │ │ │ ├── get-events-in-range.ts │ │ │ │ ├── get-sync-statuses.ts │ │ │ │ ├── list-destinations.ts │ │ │ │ ├── list-mappings.ts │ │ │ │ └── list-sources.ts │ │ │ ├── read-models.ts │ │ │ ├── routes/ │ │ │ │ └── api/ │ │ │ │ ├── accounts/ │ │ │ │ │ ├── [id].ts │ │ │ │ │ └── index.ts │ │ │ │ ├── cal/ │ │ │ │ │ └── [identifier].ts │ │ │ │ ├── destinations/ │ │ │ │ │ ├── [id].ts │ │ │ │ │ ├── authorize.ts │ │ │ │ │ ├── caldav/ │ │ │ │ │ │ ├── discover.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── callback/ │ │ │ │ │ │ └── [provider].ts │ │ │ │ │ └── index.ts │ │ │ │ ├── entitlements.ts │ │ │ │ ├── events/ │ │ │ │ │ ├── count.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── feedback/ │ │ │ │ │ └── index.ts │ │ │ │ ├── health.ts │ │ │ │ ├── ical/ │ │ │ │ │ ├── settings.ts │ │ │ │ │ └── token.ts │ │ │ │ ├── ics/ │ │ │ │ │ ├── [id]/ │ │ │ │ │ │ └── destinations.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ └── source-routes.ts │ │ │ │ ├── mappings/ │ │ │ │ │ └── index.ts │ │ │ │ ├── socket/ │ │ │ │ │ ├── token.ts │ │ │ │ │ └── url.ts │ │ │ │ ├── sources/ │ │ │ │ │ ├── [id]/ │ │ │ │ │ │ ├── destinations.ts │ │ │ │ │ │ ├── mapping-routes.ts │ │ │ │ │ │ ├── source-item-routes.ts │ │ │ │ │ │ └── sources.ts │ │ │ │ │ ├── [id].ts │ │ │ │ │ ├── authorize.ts │ │ │ │ │ ├── caldav/ │ │ │ │ │ │ ├── discover.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── callback/ │ │ │ │ │ │ └── [provider].ts │ │ │ │ │ ├── callback-state.ts │ │ │ │ │ ├── google/ │ │ │ │ │ │ ├── [id]/ │ │ │ │ │ │ │ └── destinations.ts │ │ │ │ │ │ ├── calendars.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ └── outlook/ │ │ │ │ │ ├── [id]/ │ │ │ │ │ │ └── destinations.ts │ │ │ │ │ ├── calendars.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── sync/ │ │ │ │ │ └── status.ts │ │ │ │ ├── tokens/ │ │ │ │ │ ├── [id].ts │ │ │ │ │ └── index.ts │ │ │ │ ├── v1/ │ │ │ │ │ ├── accounts/ │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── calendars/ │ │ │ │ │ │ ├── [calendarId]/ │ │ │ │ │ │ │ └── invites.ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ ├── events/ │ │ │ │ │ │ ├── [id].ts │ │ │ │ │ │ └── index.ts │ │ │ │ │ └── ical/ │ │ │ │ │ └── index.ts │ │ │ │ └── webhook/ │ │ │ │ └── polar.ts │ │ │ ├── types.ts │ │ │ └── utils/ │ │ │ ├── api-rate-limit.ts │ │ │ ├── api-tokens.ts │ │ │ ├── background-task.ts │ │ │ ├── caldav-sources.ts │ │ │ ├── caldav.ts │ │ │ ├── date-range.ts │ │ │ ├── destinations.ts │ │ │ ├── enqueue-push-sync.ts │ │ │ ├── ical-format.ts │ │ │ ├── ical.ts │ │ │ ├── invalidate-calendars.ts │ │ │ ├── logging.ts │ │ │ ├── middleware.ts │ │ │ ├── oauth-calendar-listing.ts │ │ │ ├── oauth-callback-state.ts │ │ │ ├── oauth-refresh.ts │ │ │ ├── oauth-source-credentials.ts │ │ │ ├── oauth-sources.ts │ │ │ ├── oauth.ts │ │ │ ├── provider-display.ts │ │ │ ├── request-body.ts │ │ │ ├── request-query.ts │ │ │ ├── responses.ts │ │ │ ├── route-handler.ts │ │ │ ├── safe-fetch-options.ts │ │ │ ├── source-destination-mappings.ts │ │ │ ├── source-lifecycle.ts │ │ │ ├── source-sync-defaults.ts │ │ │ ├── sources.ts │ │ │ ├── state.ts │ │ │ └── user.ts │ │ ├── tests/ │ │ │ ├── handlers/ │ │ │ │ ├── auth-oauth-resource.test.ts │ │ │ │ ├── auth.test.ts │ │ │ │ ├── websocket-initial-status.test.ts │ │ │ │ └── websocket-payload.test.ts │ │ │ ├── routes/ │ │ │ │ └── api/ │ │ │ │ ├── ical/ │ │ │ │ │ └── settings.test.ts │ │ │ │ ├── ics/ │ │ │ │ │ └── source-routes.test.ts │ │ │ │ └── sources/ │ │ │ │ └── [id]/ │ │ │ │ ├── mapping-routes.test.ts │ │ │ │ └── source-item-routes.test.ts │ │ │ └── utils/ │ │ │ ├── account-locks.test.ts │ │ │ ├── api-rate-limit.test.ts │ │ │ ├── enqueue-push-sync.test.ts │ │ │ ├── ical.test.ts │ │ │ ├── oauth-sources.test.ts │ │ │ ├── oauth.test.ts │ │ │ ├── request-body.test.ts │ │ │ ├── source-destination-mappings.test.ts │ │ │ ├── source-lifecycle.test.ts │ │ │ └── source-sync-defaults.test.ts │ │ ├── tsconfig.json │ │ ├── turbo.json │ │ └── vitest.config.ts │ ├── cron/ │ │ ├── Dockerfile │ │ ├── entrypoint.sh │ │ ├── package.json │ │ ├── scripts/ │ │ │ └── build.ts │ │ ├── src/ │ │ │ ├── context.ts │ │ │ ├── env.ts │ │ │ ├── index.ts │ │ │ ├── jobs/ │ │ │ │ ├── ingest-sources.ts │ │ │ │ ├── push-destinations.ts │ │ │ │ └── reconcile-subscriptions.ts │ │ │ ├── migration-check.ts │ │ │ └── utils/ │ │ │ ├── baker.ts │ │ │ ├── get-jobs.ts │ │ │ ├── get-sources.ts │ │ │ ├── inject-jobs.ts │ │ │ ├── logging.ts │ │ │ ├── register-jobs.ts │ │ │ ├── safe-fetch-options.ts │ │ │ ├── source-plan-selection.ts │ │ │ └── with-wide-event.ts │ │ ├── tests/ │ │ │ ├── jobs/ │ │ │ │ └── reconcile-subscriptions.test.ts │ │ │ ├── migration-check.test.ts │ │ │ └── utils/ │ │ │ ├── get-jobs.test.ts │ │ │ └── source-plan-selection.test.ts │ │ ├── tsconfig.json │ │ ├── turbo.json │ │ └── vitest.config.ts │ ├── mcp/ │ │ ├── Dockerfile │ │ ├── entrypoint.sh │ │ ├── package.json │ │ ├── scripts/ │ │ │ └── build.ts │ │ ├── src/ │ │ │ ├── context.ts │ │ │ ├── env.ts │ │ │ ├── index.ts │ │ │ ├── mcp-handler.ts │ │ │ ├── routes/ │ │ │ │ ├── health.ts │ │ │ │ └── mcp.ts │ │ │ ├── toolset.ts │ │ │ └── utils/ │ │ │ ├── logging.ts │ │ │ ├── middleware.ts │ │ │ └── route-handler.ts │ │ ├── tests/ │ │ │ ├── mcp-handler.test.ts │ │ │ └── toolset.test.ts │ │ ├── tsconfig.json │ │ └── vitest.config.ts │ └── worker/ │ ├── Dockerfile │ ├── entrypoint.sh │ ├── package.json │ ├── scripts/ │ │ └── build.ts │ ├── src/ │ │ ├── context.ts │ │ ├── env.ts │ │ ├── index.ts │ │ ├── processor.ts │ │ └── utils/ │ │ └── logging.ts │ └── tsconfig.json └── turbo.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .claude/settings.json ================================================ { "$schema": "https://json.schemastore.org/claude-code-settings.json", "hooks": { "PostToolUse": [ { "matcher": "Write|Edit", "hooks": [ { "type": "command", "command": "bun unused" }, { "type": "command", "command": "bun lint" }, { "type": "command", "command": "bun types" } ] } ] } } ================================================ FILE: .claude/skills/react-best-practices/AGENTS.md ================================================ # React Best Practices **Version 0.1.0** Vercel Engineering January 2026 > **Note:** > This document is mainly for agents and LLMs to follow when maintaining, > generating, or refactoring React and Next.js codebases at Vercel. Humans > may also find it useful, but guidance here is optimized for automation > and consistency by AI-assisted workflows. --- ## Abstract Comprehensive performance optimization guide for React and Next.js applications, designed for AI agents and LLMs. Contains 40+ rules across 8 categories, prioritized by impact from critical (eliminating waterfalls, reducing bundle size) to incremental (advanced patterns). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics to guide automated refactoring and code generation. --- ## Table of Contents 1. [Eliminating Waterfalls](#1-eliminating-waterfalls) — **CRITICAL** - 1.1 [Defer Await Until Needed](#11-defer-await-until-needed) - 1.2 [Dependency-Based Parallelization](#12-dependency-based-parallelization) - 1.3 [Prevent Waterfall Chains in API Routes](#13-prevent-waterfall-chains-in-api-routes) - 1.4 [Promise.all() for Independent Operations](#14-promiseall-for-independent-operations) - 1.5 [Strategic Suspense Boundaries](#15-strategic-suspense-boundaries) 2. [Bundle Size Optimization](#2-bundle-size-optimization) — **CRITICAL** - 2.1 [Avoid Barrel File Imports](#21-avoid-barrel-file-imports) - 2.2 [Conditional Module Loading](#22-conditional-module-loading) - 2.3 [Defer Non-Critical Third-Party Libraries](#23-defer-non-critical-third-party-libraries) - 2.4 [Dynamic Imports for Heavy Components](#24-dynamic-imports-for-heavy-components) - 2.5 [Preload Based on User Intent](#25-preload-based-on-user-intent) 3. [Server-Side Performance](#3-server-side-performance) — **HIGH** - 3.1 [Cross-Request LRU Caching](#31-cross-request-lru-caching) - 3.2 [Minimize Serialization at RSC Boundaries](#32-minimize-serialization-at-rsc-boundaries) - 3.3 [Parallel Data Fetching with Component Composition](#33-parallel-data-fetching-with-component-composition) - 3.4 [Per-Request Deduplication with React.cache()](#34-per-request-deduplication-with-reactcache) - 3.5 [Use after() for Non-Blocking Operations](#35-use-after-for-non-blocking-operations) 4. [Client-Side Data Fetching](#4-client-side-data-fetching) — **MEDIUM-HIGH** - 4.1 [Deduplicate Global Event Listeners](#41-deduplicate-global-event-listeners) - 4.2 [Use SWR for Automatic Deduplication](#42-use-swr-for-automatic-deduplication) 5. [Re-render Optimization](#5-re-render-optimization) — **MEDIUM** - 5.1 [Defer State Reads to Usage Point](#51-defer-state-reads-to-usage-point) - 5.2 [Extract to Memoized Components](#52-extract-to-memoized-components) - 5.3 [Narrow Effect Dependencies](#53-narrow-effect-dependencies) - 5.4 [Subscribe to Derived State](#54-subscribe-to-derived-state) - 5.5 [Use Functional setState Updates](#55-use-functional-setstate-updates) - 5.6 [Use Lazy State Initialization](#56-use-lazy-state-initialization) - 5.7 [Use Transitions for Non-Urgent Updates](#57-use-transitions-for-non-urgent-updates) 6. [Rendering Performance](#6-rendering-performance) — **MEDIUM** - 6.1 [Animate SVG Wrapper Instead of SVG Element](#61-animate-svg-wrapper-instead-of-svg-element) - 6.2 [CSS content-visibility for Long Lists](#62-css-content-visibility-for-long-lists) - 6.3 [Hoist Static JSX Elements](#63-hoist-static-jsx-elements) - 6.4 [Optimize SVG Precision](#64-optimize-svg-precision) - 6.5 [Prevent Hydration Mismatch Without Flickering](#65-prevent-hydration-mismatch-without-flickering) - 6.6 [Use Activity Component for Show/Hide](#66-use-activity-component-for-showhide) - 6.7 [Use Explicit Conditional Rendering](#67-use-explicit-conditional-rendering) 7. [JavaScript Performance](#7-javascript-performance) — **LOW-MEDIUM** - 7.1 [Batch DOM CSS Changes](#71-batch-dom-css-changes) - 7.2 [Build Index Maps for Repeated Lookups](#72-build-index-maps-for-repeated-lookups) - 7.3 [Cache Property Access in Loops](#73-cache-property-access-in-loops) - 7.4 [Cache Repeated Function Calls](#74-cache-repeated-function-calls) - 7.5 [Cache Storage API Calls](#75-cache-storage-api-calls) - 7.6 [Combine Multiple Array Iterations](#76-combine-multiple-array-iterations) - 7.7 [Early Length Check for Array Comparisons](#77-early-length-check-for-array-comparisons) - 7.8 [Early Return from Functions](#78-early-return-from-functions) - 7.9 [Hoist RegExp Creation](#79-hoist-regexp-creation) - 7.10 [Use Loop for Min/Max Instead of Sort](#710-use-loop-for-minmax-instead-of-sort) - 7.11 [Use Set/Map for O(1) Lookups](#711-use-setmap-for-o1-lookups) - 7.12 [Use toSorted() Instead of sort() for Immutability](#712-use-tosorted-instead-of-sort-for-immutability) 8. [Advanced Patterns](#8-advanced-patterns) — **LOW** - 8.1 [Store Event Handlers in Refs](#81-store-event-handlers-in-refs) - 8.2 [useLatest for Stable Callback Refs](#82-uselatest-for-stable-callback-refs) --- ## 1. Eliminating Waterfalls **Impact: CRITICAL** Waterfalls are the #1 performance killer. Each sequential await adds full network latency. Eliminating them yields the largest gains. ### 1.1 Defer Await Until Needed **Impact: HIGH (avoids blocking unused code paths)** Move `await` operations into the branches where they're actually used to avoid blocking code paths that don't need them. **Incorrect: blocks both branches** ```typescript async function handleRequest(userId: string, skipProcessing: boolean) { const userData = await fetchUserData(userId) if (skipProcessing) { // Returns immediately but still waited for userData return { skipped: true } } // Only this branch uses userData return processUserData(userData) } ``` **Correct: only blocks when needed** ```typescript async function handleRequest(userId: string, skipProcessing: boolean) { if (skipProcessing) { // Returns immediately without waiting return { skipped: true } } // Fetch only when needed const userData = await fetchUserData(userId) return processUserData(userData) } ``` **Another example: early return optimization** ```typescript // Incorrect: always fetches permissions async function updateResource(resourceId: string, userId: string) { const permissions = await fetchPermissions(userId) const resource = await getResource(resourceId) if (!resource) { return { error: 'Not found' } } if (!permissions.canEdit) { return { error: 'Forbidden' } } return await updateResourceData(resource, permissions) } // Correct: fetches only when needed async function updateResource(resourceId: string, userId: string) { const resource = await getResource(resourceId) if (!resource) { return { error: 'Not found' } } const permissions = await fetchPermissions(userId) if (!permissions.canEdit) { return { error: 'Forbidden' } } return await updateResourceData(resource, permissions) } ``` This optimization is especially valuable when the skipped branch is frequently taken, or when the deferred operation is expensive. ### 1.2 Dependency-Based Parallelization **Impact: CRITICAL (2-10× improvement)** For operations with partial dependencies, use `better-all` to maximize parallelism. It automatically starts each task at the earliest possible moment. **Incorrect: profile waits for config unnecessarily** ```typescript const [user, config] = await Promise.all([ fetchUser(), fetchConfig() ]) const profile = await fetchProfile(user.id) ``` **Correct: config and profile run in parallel** ```typescript import { all } from 'better-all' const { user, config, profile } = await all({ async user() { return fetchUser() }, async config() { return fetchConfig() }, async profile() { return fetchProfile((await this.$.user).id) } }) ``` Reference: [https://github.com/shuding/better-all](https://github.com/shuding/better-all) ### 1.3 Prevent Waterfall Chains in API Routes **Impact: CRITICAL (2-10× improvement)** In API routes and Server Actions, start independent operations immediately, even if you don't await them yet. **Incorrect: config waits for auth, data waits for both** ```typescript export async function GET(request: Request) { const session = await auth() const config = await fetchConfig() const data = await fetchData(session.user.id) return Response.json({ data, config }) } ``` **Correct: auth and config start immediately** ```typescript export async function GET(request: Request) { const sessionPromise = auth() const configPromise = fetchConfig() const session = await sessionPromise const [config, data] = await Promise.all([ configPromise, fetchData(session.user.id) ]) return Response.json({ data, config }) } ``` For operations with more complex dependency chains, use `better-all` to automatically maximize parallelism (see Dependency-Based Parallelization). ### 1.4 Promise.all() for Independent Operations **Impact: CRITICAL (2-10× improvement)** When async operations have no interdependencies, execute them concurrently using `Promise.all()`. **Incorrect: sequential execution, 3 round trips** ```typescript const user = await fetchUser() const posts = await fetchPosts() const comments = await fetchComments() ``` **Correct: parallel execution, 1 round trip** ```typescript const [user, posts, comments] = await Promise.all([ fetchUser(), fetchPosts(), fetchComments() ]) ``` ### 1.5 Strategic Suspense Boundaries **Impact: HIGH (faster initial paint)** Instead of awaiting data in async components before returning JSX, use Suspense boundaries to show the wrapper UI faster while data loads. **Incorrect: wrapper blocked by data fetching** ```tsx async function Page() { const data = await fetchData() // Blocks entire page return (
Sidebar
Header
Footer
) } ``` The entire layout waits for data even though only the middle section needs it. **Correct: wrapper shows immediately, data streams in** ```tsx function Page() { return (
Sidebar
Header
}>
Footer
) } async function DataDisplay() { const data = await fetchData() // Only blocks this component return
{data.content}
} ``` Sidebar, Header, and Footer render immediately. Only DataDisplay waits for data. **Alternative: share promise across components** ```tsx function Page() { // Start fetch immediately, but don't await const dataPromise = fetchData() return (
Sidebar
Header
}>
Footer
) } function DataDisplay({ dataPromise }: { dataPromise: Promise }) { const data = use(dataPromise) // Unwraps the promise return
{data.content}
} function DataSummary({ dataPromise }: { dataPromise: Promise }) { const data = use(dataPromise) // Reuses the same promise return
{data.summary}
} ``` Both components share the same promise, so only one fetch occurs. Layout renders immediately while both components wait together. **When NOT to use this pattern:** - Critical data needed for layout decisions (affects positioning) - SEO-critical content above the fold - Small, fast queries where suspense overhead isn't worth it - When you want to avoid layout shift (loading → content jump) **Trade-off:** Faster initial paint vs potential layout shift. Choose based on your UX priorities. --- ## 2. Bundle Size Optimization **Impact: CRITICAL** Reducing initial bundle size improves Time to Interactive and Largest Contentful Paint. ### 2.1 Avoid Barrel File Imports **Impact: CRITICAL (200-800ms import cost, slow builds)** Import directly from source files instead of barrel files to avoid loading thousands of unused modules. **Barrel files** are entry points that re-export multiple modules (e.g., `index.js` that does `export * from './module'`). Popular icon and component libraries can have **up to 10,000 re-exports** in their entry file. For many React packages, **it takes 200-800ms just to import them**, affecting both development speed and production cold starts. **Why tree-shaking doesn't help:** When a library is marked as external (not bundled), the bundler can't optimize it. If you bundle it to enable tree-shaking, builds become substantially slower analyzing the entire module graph. **Incorrect: imports entire library** ```tsx import { Check, X, Menu } from 'lucide-react' // Loads 1,583 modules, takes ~2.8s extra in dev // Runtime cost: 200-800ms on every cold start import { Button, TextField } from '@mui/material' // Loads 2,225 modules, takes ~4.2s extra in dev ``` **Correct: imports only what you need** ```tsx import Check from 'lucide-react/dist/esm/icons/check' import X from 'lucide-react/dist/esm/icons/x' import Menu from 'lucide-react/dist/esm/icons/menu' // Loads only 3 modules (~2KB vs ~1MB) import Button from '@mui/material/Button' import TextField from '@mui/material/TextField' // Loads only what you use ``` **Alternative: Next.js 13.5+** ```js // next.config.js - use optimizePackageImports module.exports = { experimental: { optimizePackageImports: ['lucide-react', '@mui/material'] } } // Then you can keep the ergonomic barrel imports: import { Check, X, Menu } from 'lucide-react' // Automatically transformed to direct imports at build time ``` Direct imports provide 15-70% faster dev boot, 28% faster builds, 40% faster cold starts, and significantly faster HMR. Libraries commonly affected: `lucide-react`, `@mui/material`, `@mui/icons-material`, `@tabler/icons-react`, `react-icons`, `@headlessui/react`, `@radix-ui/react-*`, `lodash`, `ramda`, `date-fns`, `rxjs`, `react-use`. Reference: [https://vercel.com/blog/how-we-optimized-package-imports-in-next-js](https://vercel.com/blog/how-we-optimized-package-imports-in-next-js) ### 2.2 Conditional Module Loading **Impact: HIGH (loads large data only when needed)** Load large data or modules only when a feature is activated. **Example: lazy-load animation frames** ```tsx function AnimationPlayer({ enabled }: { enabled: boolean }) { const [frames, setFrames] = useState(null) useEffect(() => { if (enabled && !frames && typeof window !== 'undefined') { import('./animation-frames.js') .then(mod => setFrames(mod.frames)) .catch(() => setEnabled(false)) } }, [enabled, frames]) if (!frames) return return } ``` The `typeof window !== 'undefined'` check prevents bundling this module for SSR, optimizing server bundle size and build speed. ### 2.3 Defer Non-Critical Third-Party Libraries **Impact: MEDIUM (loads after hydration)** Analytics, logging, and error tracking don't block user interaction. Load them after hydration. **Incorrect: blocks initial bundle** ```tsx import { Analytics } from '@vercel/analytics/react' export default function RootLayout({ children }) { return ( {children} ) } ``` **Correct: loads after hydration** ```tsx import dynamic from 'next/dynamic' const Analytics = dynamic( () => import('@vercel/analytics/react').then(m => m.Analytics), { ssr: false } ) export default function RootLayout({ children }) { return ( {children} ) } ``` ### 2.4 Dynamic Imports for Heavy Components **Impact: CRITICAL (directly affects TTI and LCP)** Use `next/dynamic` to lazy-load large components not needed on initial render. **Incorrect: Monaco bundles with main chunk ~300KB** ```tsx import { MonacoEditor } from './monaco-editor' function CodePanel({ code }: { code: string }) { return } ``` **Correct: Monaco loads on demand** ```tsx import dynamic from 'next/dynamic' const MonacoEditor = dynamic( () => import('./monaco-editor').then(m => m.MonacoEditor), { ssr: false } ) function CodePanel({ code }: { code: string }) { return } ``` ### 2.5 Preload Based on User Intent **Impact: MEDIUM (reduces perceived latency)** Preload heavy bundles before they're needed to reduce perceived latency. **Example: preload on hover/focus** ```tsx function EditorButton({ onClick }: { onClick: () => void }) { const preload = () => { if (typeof window !== 'undefined') { void import('./monaco-editor') } } return ( ) } ``` **Example: preload when feature flag is enabled** ```tsx function FlagsProvider({ children, flags }: Props) { useEffect(() => { if (flags.editorEnabled && typeof window !== 'undefined') { void import('./monaco-editor').then(mod => mod.init()) } }, [flags.editorEnabled]) return {children} } ``` The `typeof window !== 'undefined'` check prevents bundling preloaded modules for SSR, optimizing server bundle size and build speed. --- ## 3. Server-Side Performance **Impact: HIGH** Optimizing server-side rendering and data fetching eliminates server-side waterfalls and reduces response times. ### 3.1 Cross-Request LRU Caching **Impact: HIGH (caches across requests)** `React.cache()` only works within one request. For data shared across sequential requests (user clicks button A then button B), use an LRU cache. **Implementation:** ```typescript import { LRUCache } from 'lru-cache' const cache = new LRUCache({ max: 1000, ttl: 5 * 60 * 1000 // 5 minutes }) export async function getUser(id: string) { const cached = cache.get(id) if (cached) return cached const user = await db.user.findUnique({ where: { id } }) cache.set(id, user) return user } // Request 1: DB query, result cached // Request 2: cache hit, no DB query ``` Use when sequential user actions hit multiple endpoints needing the same data within seconds. **With Vercel's [Fluid Compute](https://vercel.com/docs/fluid-compute):** LRU caching is especially effective because multiple concurrent requests can share the same function instance and cache. This means the cache persists across requests without needing external storage like Redis. **In traditional serverless:** Each invocation runs in isolation, so consider Redis for cross-process caching. Reference: [https://github.com/isaacs/node-lru-cache](https://github.com/isaacs/node-lru-cache) ### 3.2 Minimize Serialization at RSC Boundaries **Impact: HIGH (reduces data transfer size)** The React Server/Client boundary serializes all object properties into strings and embeds them in the HTML response and subsequent RSC requests. This serialized data directly impacts page weight and load time, so **size matters a lot**. Only pass fields that the client actually uses. **Incorrect: serializes all 50 fields** ```tsx async function Page() { const user = await fetchUser() // 50 fields return } 'use client' function Profile({ user }: { user: User }) { return
{user.name}
// uses 1 field } ``` **Correct: serializes only 1 field** ```tsx async function Page() { const user = await fetchUser() return } 'use client' function Profile({ name }: { name: string }) { return
{name}
} ``` ### 3.3 Parallel Data Fetching with Component Composition **Impact: CRITICAL (eliminates server-side waterfalls)** React Server Components execute sequentially within a tree. Restructure with composition to parallelize data fetching. **Incorrect: Sidebar waits for Page's fetch to complete** ```tsx export default async function Page() { const header = await fetchHeader() return (
{header}
) } async function Sidebar() { const items = await fetchSidebarItems() return } ``` **Correct: both fetch simultaneously** ```tsx async function Header() { const data = await fetchHeader() return
{data}
} async function Sidebar() { const items = await fetchSidebarItems() return } export default function Page() { return (
) } ``` **Alternative with children prop:** ```tsx async function Layout({ children }: { children: ReactNode }) { const header = await fetchHeader() return (
{header}
{children}
) } async function Sidebar() { const items = await fetchSidebarItems() return } export default function Page() { return ( ) } ``` ### 3.4 Per-Request Deduplication with React.cache() **Impact: MEDIUM (deduplicates within request)** Use `React.cache()` for server-side request deduplication. Authentication and database queries benefit most. **Usage:** ```typescript import { cache } from 'react' export const getCurrentUser = cache(async () => { const session = await auth() if (!session?.user?.id) return null return await db.user.findUnique({ where: { id: session.user.id } }) }) ``` Within a single request, multiple calls to `getCurrentUser()` execute the query only once. ### 3.5 Use after() for Non-Blocking Operations **Impact: MEDIUM (faster response times)** Use Next.js's `after()` to schedule work that should execute after a response is sent. This prevents logging, analytics, and other side effects from blocking the response. **Incorrect: blocks response** ```tsx import { logUserAction } from '@/app/utils' export async function POST(request: Request) { // Perform mutation await updateDatabase(request) // Logging blocks the response const userAgent = request.headers.get('user-agent') || 'unknown' await logUserAction({ userAgent }) return new Response(JSON.stringify({ status: 'success' }), { status: 200, headers: { 'Content-Type': 'application/json' } }) } ``` **Correct: non-blocking** ```tsx import { after } from 'next/server' import { headers, cookies } from 'next/headers' import { logUserAction } from '@/app/utils' export async function POST(request: Request) { // Perform mutation await updateDatabase(request) // Log after response is sent after(async () => { const userAgent = (await headers()).get('user-agent') || 'unknown' const sessionCookie = (await cookies()).get('session-id')?.value || 'anonymous' logUserAction({ sessionCookie, userAgent }) }) return new Response(JSON.stringify({ status: 'success' }), { status: 200, headers: { 'Content-Type': 'application/json' } }) } ``` The response is sent immediately while logging happens in the background. **Common use cases:** - Analytics tracking - Audit logging - Sending notifications - Cache invalidation - Cleanup tasks **Important notes:** - `after()` runs even if the response fails or redirects - Works in Server Actions, Route Handlers, and Server Components Reference: [https://nextjs.org/docs/app/api-reference/functions/after](https://nextjs.org/docs/app/api-reference/functions/after) --- ## 4. Client-Side Data Fetching **Impact: MEDIUM-HIGH** Automatic deduplication and efficient data fetching patterns reduce redundant network requests. ### 4.1 Deduplicate Global Event Listeners **Impact: LOW (single listener for N components)** Use `useSWRSubscription()` to share global event listeners across component instances. **Incorrect: N instances = N listeners** ```tsx function useKeyboardShortcut(key: string, callback: () => void) { useEffect(() => { const handler = (e: KeyboardEvent) => { if (e.metaKey && e.key === key) { callback() } } window.addEventListener('keydown', handler) return () => window.removeEventListener('keydown', handler) }, [key, callback]) } ``` When using the `useKeyboardShortcut` hook multiple times, each instance will register a new listener. **Correct: N instances = 1 listener** ```tsx import useSWRSubscription from 'swr/subscription' // Module-level Map to track callbacks per key const keyCallbacks = new Map void>>() function useKeyboardShortcut(key: string, callback: () => void) { // Register this callback in the Map useEffect(() => { if (!keyCallbacks.has(key)) { keyCallbacks.set(key, new Set()) } keyCallbacks.get(key)!.add(callback) return () => { const set = keyCallbacks.get(key) if (set) { set.delete(callback) if (set.size === 0) { keyCallbacks.delete(key) } } } }, [key, callback]) useSWRSubscription('global-keydown', () => { const handler = (e: KeyboardEvent) => { if (e.metaKey && keyCallbacks.has(e.key)) { keyCallbacks.get(e.key)!.forEach(cb => cb()) } } window.addEventListener('keydown', handler) return () => window.removeEventListener('keydown', handler) }) } function Profile() { // Multiple shortcuts will share the same listener useKeyboardShortcut('p', () => { /* ... */ }) useKeyboardShortcut('k', () => { /* ... */ }) // ... } ``` ### 4.2 Use SWR for Automatic Deduplication **Impact: MEDIUM-HIGH (automatic deduplication)** SWR enables request deduplication, caching, and revalidation across component instances. **Incorrect: no deduplication, each instance fetches** ```tsx function UserList() { const [users, setUsers] = useState([]) useEffect(() => { fetch('/api/users') .then(r => r.json()) .then(setUsers) }, []) } ``` **Correct: multiple instances share one request** ```tsx import useSWR from 'swr' function UserList() { const { data: users } = useSWR('/api/users', fetcher) } ``` **For immutable data:** ```tsx import { useImmutableSWR } from '@/lib/swr' function StaticContent() { const { data } = useImmutableSWR('/api/config', fetcher) } ``` **For mutations:** ```tsx import { useSWRMutation } from 'swr/mutation' function UpdateButton() { const { trigger } = useSWRMutation('/api/user', updateUser) return } ``` Reference: [https://swr.vercel.app](https://swr.vercel.app) --- ## 5. Re-render Optimization **Impact: MEDIUM** Reducing unnecessary re-renders minimizes wasted computation and improves UI responsiveness. ### 5.1 Defer State Reads to Usage Point **Impact: MEDIUM (avoids unnecessary subscriptions)** Don't subscribe to dynamic state (searchParams, localStorage) if you only read it inside callbacks. **Incorrect: subscribes to all searchParams changes** ```tsx function ShareButton({ chatId }: { chatId: string }) { const searchParams = useSearchParams() const handleShare = () => { const ref = searchParams.get('ref') shareChat(chatId, { ref }) } return } ``` **Correct: reads on demand, no subscription** ```tsx function ShareButton({ chatId }: { chatId: string }) { const handleShare = () => { const params = new URLSearchParams(window.location.search) const ref = params.get('ref') shareChat(chatId, { ref }) } return } ``` ### 5.2 Extract to Memoized Components **Impact: MEDIUM (enables early returns)** Extract expensive work into memoized components to enable early returns before computation. **Incorrect: computes avatar even when loading** ```tsx function Profile({ user, loading }: Props) { const avatar = useMemo(() => { const id = computeAvatarId(user) return }, [user]) if (loading) return return
{avatar}
} ``` **Correct: skips computation when loading** ```tsx const UserAvatar = memo(function UserAvatar({ user }: { user: User }) { const id = useMemo(() => computeAvatarId(user), [user]) return }) function Profile({ user, loading }: Props) { if (loading) return return (
) } ``` **Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, manual memoization with `memo()` and `useMemo()` is not necessary. The compiler automatically optimizes re-renders. ### 5.3 Narrow Effect Dependencies **Impact: LOW (minimizes effect re-runs)** Specify primitive dependencies instead of objects to minimize effect re-runs. **Incorrect: re-runs on any user field change** ```tsx useEffect(() => { console.log(user.id) }, [user]) ``` **Correct: re-runs only when id changes** ```tsx useEffect(() => { console.log(user.id) }, [user.id]) ``` **For derived state, compute outside effect:** ```tsx // Incorrect: runs on width=767, 766, 765... useEffect(() => { if (width < 768) { enableMobileMode() } }, [width]) // Correct: runs only on boolean transition const isMobile = width < 768 useEffect(() => { if (isMobile) { enableMobileMode() } }, [isMobile]) ``` ### 5.4 Subscribe to Derived State **Impact: MEDIUM (reduces re-render frequency)** Subscribe to derived boolean state instead of continuous values to reduce re-render frequency. **Incorrect: re-renders on every pixel change** ```tsx function Sidebar() { const width = useWindowWidth() // updates continuously const isMobile = width < 768 return