fix: pass the actual previous step in the Tour show event - #3472
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesShow event payload
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
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 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. Comment |
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (1)
🛟 Help
|
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
shepherd.js/src/tour.tsshepherd.js/test/unit/tour.spec.js
`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>
47d6f0c to
488a510
Compare

The
showevent payload has always reportedpreviousincorrectly.The bug
Tour._showStepreassignedcurrentStepbefore building the event payload:So
previousread 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:The behavior contradicted the docs, so consumers relying on
previousto detect direction or clean up the outgoing step got the wrong object.The fix
Capture
currentStepbefore the reassignment, normalized tonull:The
?? nullmatters becausecurrentStepisStep | null | undefinedand onlystart()initializes it tonull.removeStep()sets it toundefinedbefore callingshow(0), so without normalizing, that path reportedprevious: undefinedwhile the start path reportednull. Nowpreviousis consistentlynullwhen nothing was showing before.Placing this in
_showStepcovers every route into it, including the asyncwaitForElementpath added in #3471.Notes
_showStep. It was deliberately left out of that PR to avoid bundling a public event-payload change into a feature PR. Rebased onto feat: add waitForElement and skipMissingElement step options #3471 after it landed.previousas an alias forstepwill now get the real previous step, ornullon the first step.Testing
Two unit tests in
shepherd.js/test/unit/tour.spec.js:show,previousis the step that was showing before and is not the same object asstep.removeSteppath,previousisnullrather thanundefined.Both were verified to fail against the unfixed code and pass with the fix.
pnpm test:unit:ci— 216 passedpnpm -F shepherd.js types:check:esm— cleanpnpm -F shepherd.js lint— clean🤖 Generated with Claude Code