Skip to content

fix: pass the actual previous step in the Tour show event - #3472

Merged
chuckcarpenter merged 2 commits into
mainfrom
claude/infallible-chaum-5821d5
Aug 12, 2026
Merged

fix: pass the actual previous step in the Tour show event#3472
chuckcarpenter merged 2 commits into
mainfrom
claude/infallible-chaum-5821d5

Conversation

@chuckcarpenter

@chuckcarpenter chuckcarpenter commented Aug 12, 2026

Copy link
Copy Markdown
Member

The show event payload has always reported previous incorrectly.

The bug

Tour._showStep reassigned currentStep before building the event payload:

this.currentStep = step;
this.trigger("show", {
  step,
  previous: this.currentStep  // already reassigned — same object as `step`
});

So previous read back the step being shown. It was always === step, and never the step that was actually showing before.

The documented contract

docs-src/src/content/docs/guides/usage.md ("Tour Events") states:

show: Triggered with a hash of the step and the previous step

The behavior contradicted the docs, so consumers relying on previous to detect direction or clean up the outgoing step got the wrong object.

The fix

Capture currentStep before the reassignment, normalized to null:

const previous = this.currentStep ?? null;

this.currentStep = step;
this.trigger("show", { step, previous });

The ?? null matters because currentStep is Step | null | undefined and only start() initializes it to null. removeStep() sets it to undefined before calling show(0), so without normalizing, that path reported previous: undefined while the start path reported null. Now previous is consistently null when nothing was showing before.

Placing this in _showStep covers every route into it, including the async waitForElement path added in #3471.

Notes

Testing

Two unit tests in shepherd.js/test/unit/tour.spec.js:

  1. On the second show, previous is the step that was showing before and is not the same object as step.
  2. Via the removeStep path, previous is null rather than undefined.

Both were verified to fail against the unfixed code and pass with the fix.

  • pnpm test:unit:ci — 216 passed
  • pnpm -F shepherd.js types:check:esm — clean
  • pnpm -F shepherd.js lint — clean

🤖 Generated with Claude Code

@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
shepherd-docs Ready Ready Preview Aug 12, 2026 12:43pm
shepherd-landing Ready Ready Preview Aug 12, 2026 12:43pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 118c5981-b74c-4104-bf07-278fcb644e0d

📥 Commits

Reviewing files that changed from the base of the PR and between 47d6f0c and 488a510.

📒 Files selected for processing (2)
  • shepherd.js/src/tour.ts
  • shepherd.js/test/unit/tour.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • shepherd.js/src/tour.ts

📝 Walkthrough

Walkthrough

Tour.show now captures the prior step before selecting the new step and passes it in the show event. Unit tests cover initial display, navigation, and current-step removal.

Changes

Show event payload

Layer / File(s) Summary
Capture and validate the previous step
shepherd.js/src/tour.ts, shepherd.js/test/unit/tour.spec.js
Tour.show reports the actual prior step as previous. Tests verify null on the first display, the prior step during navigation, and null after removing the current step.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix to the Tour show event's previous step value.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/infallible-chaum-5821d5

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

shepherd.js/test/unit/tour.spec.js

(node:2) ESLintIgnoreWarning: The ".eslintignore" file is no longer supported. Switch to using the "ignores" property in "eslint.config.js": https://eslint.org/docs/latest/use/configure/migration-guide#ignore-files
(Use node --trace-warnings ... to show where the warning was created)

Oops! Something went wrong! :(

ESLint: 10.8.1

A config object is using the "root" key, which is not supported in flat config system.

Flat configs always act as if they are the root config file, so this key can be safely removed.


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.

@qltysh

qltysh Bot commented Aug 12, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (1)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
shepherd.js/src/tour.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shepherd.js/src/tour.ts`:
- Around line 333-338: Update the previous-step capture in Tour.show around
this.currentStep so it normalizes an uninitialized value with a nullish fallback
to null before assigning the new step. Preserve the existing event payload and
assignment behavior, ensuring the first show event reports previous as null.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c4c160dd-66f2-4916-868f-54ca5b5c9433

📥 Commits

Reviewing files that changed from the base of the PR and between 1991f23 and 2609c7d.

📒 Files selected for processing (2)
  • shepherd.js/src/tour.ts
  • shepherd.js/test/unit/tour.spec.js

Comment thread shepherd.js/src/tour.ts Outdated
chuckcarpenter and others added 2 commits August 12, 2026 14:41
`show()` assigned `this.currentStep = step` before building the event
payload, so `previous` read back the step being shown and was always the
same object as `step`. Capture `currentStep` before the reassignment.

The documented contract (docs-src/src/content/docs/guides/usage.md,
"Tour Events") is that `show` is "Triggered with a hash of the `step` and
the `previous` step", so `previous` never reflecting the prior step
contradicted the docs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ayload

`currentStep` is `Step | null | undefined`, and only `start()` initializes
it to `null`. `removeStep()` sets it to `undefined` before showing the next
step, so that path reported `previous: undefined` while the start path
reported `null`. Normalize with `?? null` so `previous` is consistent
across every route into `show()`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chuckcarpenter
chuckcarpenter force-pushed the claude/infallible-chaum-5821d5 branch from 47d6f0c to 488a510 Compare August 12, 2026 12:42
@chuckcarpenter
chuckcarpenter merged commit 4b101e1 into main Aug 12, 2026
8 checks passed
@chuckcarpenter
chuckcarpenter deleted the claude/infallible-chaum-5821d5 branch August 12, 2026 12:47
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant