Skip to content

Conversation

@RobbieTheWagner
Copy link
Member

@RobbieTheWagner RobbieTheWagner commented Dec 27, 2025

Closes #3316

Summary by CodeRabbit

  • New Features

    • Guided tour (Demo) reliably starts across navigations, supports auto-start after redirect, and re-initializes on page transitions.
  • Documentation

    • Updated Shepherd.js integration to a newer release (CDN/module and stylesheet references updated).

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
shepherd-docs Ready Ready Preview, Comment Dec 27, 2025 5:42pm
shepherd-landing Ready Ready Preview, Comment Dec 27, 2025 5:42pm

@coderabbitai
Copy link

coderabbitai bot commented Dec 27, 2025

📝 Walkthrough

Walkthrough

Updated Shepherd import/entrypoints and CDN references (v15 → v17). Added cross-page tour coordination: Header sets sessionStorage.startTourOnLoad and navigates to / on Demo, while the index page initializes/restarts the tour on load, astro:page-load, or a dispatched startTour event.

Changes

Cohort / File(s) Summary
Docs CDN update
docs-src/src/content/docs/guides/install.mdx
Bumped Shepherd CDN references from v15.0.0v17.0.0 for the JS module and CSS.
Header demo navigation & handler
landing/src/components/Header.astro
Added client-side script to attach a single Demo click handler: sets sessionStorage.startTourOnLoad and navigates to / when off-home, or dispatches startTour when on-home; re-attaches on Astro page-load.
Index page tour init & SPA integration
landing/src/pages/index.astro
Changed Shepherd import to shepherd.js/dist/js/shepherd.mjs; auto-starts tour if sessionStorage.startTourOnLoad is set, subscribes to startTour event, manages listener lifecycle with AbortController, and re-initializes on astro:page-load.
Local demo import path
shepherd.js/dummy/index.html
Updated module import path from ../dist/esm/shepherd.mjs../dist/js/shepherd.mjs.
Package entry point
shepherd.js/package.json
Updated main field from ./dist/cjs/shepherd.cjs./dist/js/shepherd.mjs.

Sequence Diagrams

sequenceDiagram
    participant User as User
    participant Header as Header (client script)
    participant Session as sessionStorage
    participant Router as Browser / Router
    participant Index as Index Page (init)
    participant Shepherd as Shepherd instance

    User->>Header: Click "Demo"
    alt not on "/"
        Header->>Session: set startTourOnLoad = "1"
        Header->>Router: navigate to "/"
        Router->>Index: load / astro:page-load
        Index->>Session: read startTourOnLoad
        alt flag present
            Index->>Session: remove startTourOnLoad
            Index->>Shepherd: initialize → start()
        else
            Index->>Shepherd: initialize (ready)
        end
    else already on "/"
        Header->>Index: dispatch "startTour"
        Index->>Shepherd: start()
    end

    Note right of Index: re-attaches init on astro:page-load for SPA navigation
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hop and tap the Demo bell,

A flag, a route, the tour will swell.
Across the pages, gentle and spry,
Shepherd starts when banners fly.
v17 leads the hop — hi‑fi!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated changes: CDN version upgrades for Shepherd.js (15.0.0 to 17.0.0) and changes to the main entry point in package.json are out of scope for fixing the demo functionality. Separate the Shepherd.js version upgrade and package.json changes into a dedicated PR; retain only the demo redirect/navigation logic changes in this PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Redirect to root when starting demo' is specific, concise, and directly reflects the main change: adding navigation logic to redirect to the root path when starting the demo tour.
Linked Issues check ✅ Passed The PR implements navigation redirection when starting the demo and event coordination via sessionStorage, which addresses the non-functional demo issue #3316 by ensuring proper demo initialization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch demo-redirect

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs-src/src/content/docs/guides/install.mdx (1)

47-58: Inconsistent version reference in documentation.

Line 47 mentions "v10.0.1" as an example version, but the code snippet uses v17.0.0. Update the text to match the actual version shown in the code.

🔎 Suggested fix
-You can use jsDelivr to pull down any release from npm. For example, you could include v10.0.1 with styles in your app
+You can use jsDelivr to pull down any release from npm. For example, you could include v17.0.0 with styles in your app
🧹 Nitpick comments (1)
landing/src/components/Header.astro (1)

177-187: Consider normalizing pathname for edge cases.

The pathname check window.location.pathname !== '/' may not handle edge cases where the pathname could be an empty string or have a trailing slash variation. Consider normalizing:

🔎 Suggested improvement
     newBtn.addEventListener('click', () => {
       // Check if we're on the home page
-      if (window.location.pathname !== '/') {
+      const isHome = window.location.pathname === '/' || window.location.pathname === '';
+      if (!isHome) {
         // Store flag to start tour after navigation
         sessionStorage.setItem('startTourOnLoad', 'true');
         window.location.href = '/';
       } else {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ad2839 and f96a535.

📒 Files selected for processing (5)
  • docs-src/src/content/docs/guides/install.mdx
  • landing/src/components/Header.astro
  • landing/src/pages/index.astro
  • shepherd.js/dummy/index.html
  • shepherd.js/package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests
🔇 Additional comments (4)
shepherd.js/dummy/index.html (1)

125-125: LGTM!

The import path update aligns with the new distribution structure.

landing/src/components/Header.astro (1)

190-195: LGTM!

The dual event listener setup correctly handles both the initial page load (DOMContentLoaded) and Astro's client-side navigation (astro:page-load).

landing/src/pages/index.astro (2)

305-309: LGTM!

The ready() function correctly sets up listeners for both initial load and Astro page transitions.


26-28: LGTM!

The script path in the code example is consistent with the updated distribution structure.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
landing/src/pages/index.astro (2)

97-103: Auto-start logic looks good.

The sessionStorage-based coordination correctly enables the cross-page demo flow: the Header component sets the flag and navigates, then this page auto-starts the tour on load. The check-and-remove pattern prevents duplicate starts.

💡 Optional: Add comment explaining the cross-page coordination
        
-       // Check if we should auto-start the tour (after redirect from another page)
+       // Cross-page coordination: Header's Demo button sets this flag and navigates here,
+       // triggering an auto-start. Remove the flag to prevent re-starting on refresh.
        const shouldStartTour = sessionStorage.getItem('startTourOnLoad');
        if (shouldStartTour) {
          sessionStorage.removeItem('startTourOnLoad');
          shepherd.start();
        }

95-95: Document the timeout duration.

The 400ms timeout is a magic number with no explanation. While it may work in practice, documenting why this specific duration was chosen would help future maintainers.

💡 Optional: Add explanation for the timeout
-     // wait for shepherd to be ready
+     // Wait for Shepherd to be ready and DOM to fully render
+     // 400ms empirically determined to be sufficient for initialization
      setTimeout(function () {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3041fd and 5277825.

📒 Files selected for processing (1)
  • landing/src/pages/index.astro
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests
🔇 Additional comments (1)
landing/src/pages/index.astro (1)

105-115: AbortController pattern correctly addresses past review feedback.

The implementation properly prevents event listener accumulation across Astro page transitions by:

  • Aborting any existing listener before adding a new one
  • Storing the AbortController on window for lifecycle management
  • Passing the signal to addEventListener

This matches the recommended fix from the previous review.

@RobbieTheWagner RobbieTheWagner merged commit 6b1bbd9 into main Dec 27, 2025
6 of 7 checks passed
@RobbieTheWagner RobbieTheWagner deleted the demo-redirect branch December 27, 2025 17:44
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
landing/src/pages/index.astro (1)

105-115: Excellent fix for listener accumulation.

The AbortController pattern correctly prevents duplicate event listeners from accumulating across page transitions. The implementation properly aborts the previous listener before registering a new one.

Optional: Improve type safety

Consider extending the Window interface instead of using any casts:

Add at the top of the script block:

declare global {
  interface Window {
    __startTourAbortController?: AbortController;
  }
}

Then replace the casts:

-        if ((window as any).__startTourAbortController) {
-          (window as any).__startTourAbortController.abort();
+        if (window.__startTourAbortController) {
+          window.__startTourAbortController.abort();
         }
         
         const controller = new AbortController();
-        (window as any).__startTourAbortController = controller;
+        window.__startTourAbortController = controller;
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5277825 and 5b0d5b8.

📒 Files selected for processing (1)
  • landing/src/pages/index.astro
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests
🔇 Additional comments (3)
landing/src/pages/index.astro (3)

315-316: Correct fix for double initialization.

Removing the DOMContentLoaded listener and relying solely on astro:page-load is the right approach. This event fires on both initial page load and subsequent navigations, eliminating the redundant initialization that occurred previously.


97-103: Auto-start logic is correct.

The sessionStorage key startTourOnLoad is consistently used across both the Header component (sets the flag and redirects) and the index page (reads, removes, and starts the tour). The implementation properly cleans up the flag after use to prevent duplicate auto-starts.


27-27: The script path update to shepherd.js/dist/js/shepherd.mjs is correct and matches the package's configured exports in package.json.

@github-actions github-actions bot mentioned this pull request Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shepherdjs.dev demo doesn't work

2 participants