Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com

Fix the visibility of the intro state #36

Mergedfukomerged 6 commits intomain fromrefs/pull/36/headmerged by fuko View on GitHub

fukocommented
  • The Cookie Store API is too new, it's not supported by some older browser versions yet
  • Remove some redundant code
  • Use a cookie for storing the showIntro state

Summary by CodeRabbit

  • Refactor

    • Tutorial intro visibility is now state-driven and persisted across sessions (cookie-backed); intro is no longer controlled via URL query.
    • Intro component and route now consume a shared showIntro state/utility for consistent behavior.
  • Chores

    • Lint configuration updated with an additional rule setting.
✏️ Tip: You can customize this high-level summary in your review settings.
    1. Walkthrough

      Refactors tutorial intro state from a query-parameter string to a cookie-backed, isomorphic state. Adds getShowIntro utility, updates route loaders and HomeIntro props to use a boolean showIntro, and adjusts a linter rule in biome.json.

      Changes

      Cohort / File(s)Summary
      Configuration
      biome.json
      Added noDocumentCookie: "off" under linter.suspicious.
      Component Signature Update
      src/components/HomeIntro.tsx
      HomeIntro prop changed from `intro: "true"
      Route Config (small)
      src/routes/_tutorial._db.projects.tsx
      Removed the loader property; route now only includes component and ssr: false.
      Route Loader & Data Flow Refactor
      src/routes/_tutorial.tsx
      Removed mock user/beforeLoad and intro from search validation; integrated getShowIntro in loader and return value; HomeIntro now receives showIntro boolean derived from showIntroState.
      New Isomorphic Utility
      src/utils/getShowIntro.ts
      New isomorphic getShowIntro() exposing { showIntroState, updateShowIntro }; server reads/writes cookie via getCookie/setCookie (1 year), client reads/writes document.cookie; zod schema enforces `"hidden"
      Utility Minor Edit
      src/utils/getTutorialDataHandlers.ts
      Removed a comment; no functional changes.

      Sequence Diagram(s)

      sequenceDiagram
          participant Browser as User/Browser
          participant Route as Route Loader
          participant GetShowIntro as getShowIntro
          participant Server as Server Cookies
          participant HomeIntro as HomeIntro Component
      
          Browser->>Route: Request /tutorial
          Route->>GetShowIntro: getShowIntro() (server impl)
          GetShowIntro->>Server: read INTRO_COOKIE_NAME
          Server-->>GetShowIntro: cookie value / default "visible"
          GetShowIntro-->>Route: { showIntroState, updateShowIntro }
          Route-->>HomeIntro: pass showIntro (showIntroState === "visible")
          HomeIntro->>Browser: render UI based on showIntro
          HomeIntro->>GetShowIntro: updateShowIntro("hidden") on dismiss
          GetShowIntro->>Server: set INTRO_COOKIE_NAME="hidden" (max-age=1 year)

      Estimated code review effort

      🎯 4 (Complex) | ⏱️ ~45 minutes

      Pre-merge checks and finishing touches

      ❌ Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.You can run @coderabbitai generate docstrings to improve docstring coverage.
      ✅ Passed checks (2 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title 'Fix the visibility of the intro state' accurately describes the main objective of the PR, which centers on managing intro visibility through a cookie-based approach for better browser compatibility.
      ✨ Finishing touches
      • 📝 Generate docstrings

      📜 Recent review details

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between 6b6147949ac7fcf0141be6c7f718032746aba394 and ea00aaab01c96da1258fc680fa66690201a866ae.

      📒 Files selected for processing (2)
      • src/components/HomeIntro.tsx
      • src/utils/getShowIntro.ts
      🚧 Files skipped from review as they are similar to previous changes (1)
      • src/components/HomeIntro.tsx
      🧰 Additional context used
      📓 Path-based instructions (3)
      src/**/*.{ts,tsx,js,jsx}

      📄 CodeRabbit inference engine (AGENTS.md)

      Always ensure no formatting/linting issues exist in code - use pnpm check --fix to automatically fix issues

      Files:

      • src/utils/getShowIntro.ts
      **/*.{tsx,ts}

      📄 CodeRabbit inference engine (AGENTS.md)

      Prefer functions over arrow functions for React components

      Files:

      • src/utils/getShowIntro.ts
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (AGENTS.md)

      Prefer type over interface for type definitions

      Files:

      • src/utils/getShowIntro.ts
      🔇 Additional comments (2)
      src/utils/getShowIntro.ts (2)

      16-28: LGTM!

      The server-side implementation correctly uses getCookie/setCookie from TanStack Start, and the zod schema with .catch("visible") ensures graceful handling of missing or invalid cookie values.


      29-43: LGTM!

      The client-side cookie parsing works correctly for the constrained value set ("hidden" | "visible"). The zod schema with .catch("visible") provides appropriate fallback handling.


      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. 🚀 Preview Deployment

      Status: ✅ Ready!

      Preview URL: Open Preview

      Commit: ea00aaab01c96da1258fc680fa66690201a866ae

      Built and deployed successfully

    3. Actionable comments posted: 1

      🧹 Nitpick comments (2)
      src/utils/getShowIntro.ts (1)

      20-25: Consider extracting the max-age constant to avoid duplication.

      The 1-year max-age calculation is duplicated between server and client implementations.

      🔎 Proposed refactor
       const INTRO_COOKIE_NAME = "intro-visibility";
      +const INTRO_COOKIE_MAX_AGE = 60 * 60 * 24 * 365; // 1 year
      
       const showIntroSchema = z.enum(["hidden", "visible"]).catch("visible");

      Then use INTRO_COOKIE_MAX_AGE in both implementations. This follows the pattern used in sidebar.tsx with SIDEBAR_COOKIE_MAX_AGE.

      Also applies to: 36-41

      src/components/HomeIntro.tsx (1)

      76-81: Consider memoizing the getShowIntro() call.

      getShowIntro() creates a new updateShowIntro function reference on each render, causing startTutorial to be recreated every time despite useCallback. This is unlikely to cause issues given the component's usage, but could be optimized.

      🔎 Proposed refactor
      +import { useMemo } from "react";
       // ...
      -  const { updateShowIntro } = getShowIntro();
      +  const { updateShowIntro } = useMemo(() => getShowIntro(), []);

      Alternatively, since updateShowIntro doesn't depend on any reactive values, you could remove it from the dependency array and use an eslint-disable comment, though that's less idiomatic.

      📜 Review details

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between 7fa9ca714c3f03bde2d10ae0931a01a559415eb6 and 6b6147949ac7fcf0141be6c7f718032746aba394.

      📒 Files selected for processing (6)
      • biome.json
      • src/components/HomeIntro.tsx
      • src/routes/_tutorial._db.projects.tsx
      • src/routes/_tutorial.tsx
      • src/utils/getShowIntro.ts
      • src/utils/getTutorialDataHandlers.ts
      💤 Files with no reviewable changes (2)
      • src/routes/_tutorial._db.projects.tsx
      • src/utils/getTutorialDataHandlers.ts
      🧰 Additional context used
      📓 Path-based instructions (3)
      src/**/*.{ts,tsx,js,jsx}

      📄 CodeRabbit inference engine (AGENTS.md)

      Always ensure no formatting/linting issues exist in code - use pnpm check --fix to automatically fix issues

      Files:

      • src/utils/getShowIntro.ts
      • src/components/HomeIntro.tsx
      • src/routes/_tutorial.tsx
      **/*.{tsx,ts}

      📄 CodeRabbit inference engine (AGENTS.md)

      Prefer functions over arrow functions for React components

      Files:

      • src/utils/getShowIntro.ts
      • src/components/HomeIntro.tsx
      • src/routes/_tutorial.tsx
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (AGENTS.md)

      Prefer type over interface for type definitions

      Files:

      • src/utils/getShowIntro.ts
      • src/components/HomeIntro.tsx
      • src/routes/_tutorial.tsx
      🧠 Learnings (3)
      📚 Learning: 2025-12-24T15:25:07.106Z
      Learnt from: fulopkovacs
      Repo: fulopkovacs/trytanstackdb.com PR: 22
      File: src/components/TodoBoards.tsx:63-81
      Timestamp: 2025-12-24T15:25:07.106Z
      Learning: In Tailwind CSS v4, prefer canonical classes using bg-linear-to-* (e.g., bg-linear-to-b, bg-linear-to-t, bg-linear-to-r) over the older bg-gradient-to-* syntax. This aligns with Tailwind LSP's suggestCanonicalClasses rule. Apply across TSX files (e.g., src/components/*.tsx); replace occurrences of bg-gradient-to-* with the corresponding bg-linear-to-* equivalents and verify gradients visually.

      Applied to files:

      • src/components/HomeIntro.tsx
      • src/routes/_tutorial.tsx
      📚 Learning: 2025-12-28T23:34:13.416Z
      Learnt from: fulopkovacs
      Repo: fulopkovacs/trytanstackdb.com PR: 32
      File: src/components/HomeIntro.tsx:16-25
      Timestamp: 2025-12-28T23:34:13.416Z
      Learning: In Motion (motion/react), when configuring variant transitions, use delayChildren: stagger(x) to create per-child delays (e.g., delayChildren: stagger(0.2)). This is different from the older API that used a separate staggerChildren property. Apply this guidance to TSX files that declare motion variants (e.g., in src/components/**/*.tsx) and verify that stagger is imported from framer-motion. Ensure transitions reflect the intended stagger timing and that no conflicting delay values override the staggered effect.

      Applied to files:

      • src/components/HomeIntro.tsx
      • src/routes/_tutorial.tsx
      📚 Learning: 2025-12-29T13:20:08.377Z
      Learnt from: CR
      Repo: fulopkovacs/trytanstackdb.com PR: 0
      File: AGENTS.md:0-0
      Timestamp: 2025-12-29T13:20:08.377Z
      Learning: Applies to src/route/__root.tsx : The root route is located at `src/route/__root.tsx` in this TanStack Start project

      Applied to files:

      • src/routes/_tutorial.tsx
      🧬 Code graph analysis (2)
      src/utils/getShowIntro.ts (2)
      src/utils/getTutorialDataHandlers.ts (2)
      • Promise (73-86)
      • data (96-113)
      src/components/ui/sidebar.tsx (1)
      • value (83-93)
      src/components/HomeIntro.tsx (1)
      src/utils/getShowIntro.ts (1)
      • getShowIntro (15-43)
      🔇 Additional comments (5)
      biome.json (1)

      38-41: LGTM!

      Disabling noDocumentCookie is appropriate given the PR's shift to cookie-based state management for intro visibility. This aligns with the existing pattern in sidebar.tsx which also uses document.cookie directly.

      src/utils/getShowIntro.ts (1)

      15-43: LGTM!

      The isomorphic implementation correctly separates server and client concerns. The use of z.enum().catch() for schema validation with a safe fallback is a solid pattern.

      src/components/HomeIntro.tsx (1)

      63-68: LGTM on the prop signature change.

      Changing from intro: "true" | "false" | undefined to showIntro: boolean is cleaner and aligns better with how the value is used in the component logic.

      src/routes/_tutorial.tsx (2)

      16-23: LGTM!

      The loader correctly integrates getShowIntro() alongside the existing tutorial data handler. Returning both values in the loader ensures the intro state is available server-side for SSR.


      27-39: LGTM!

      The component cleanly consumes the loader data and converts showIntroState to a boolean for HomeIntro. This keeps the prop interface simple and the conversion logic centralized in the route.

      OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)
    4. fuko merged this897d672

    5. fuko closed this

Sign in to join this conversation.