fix: not call destroy on destroyed step#3455
Conversation
|
Someone is attempting to deploy a commit to the shipshapecode Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughIn ChangesStep teardown sentinel fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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/step.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.4.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 |
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/step.ts`:
- Line 450: The teardown at line 450 assigns `undefined` to this.el, but the
getElement() method's contract and type signature indicate it returns null for
destroyed steps. Revert line 450 to assign null instead of undefined to maintain
the documented contract. Then update the guard logic in _setupElements() to
check if this.el is either null or undefined (treating both as "not mounted") to
handle any edge cases where undefined might be present from other code paths.
🪄 Autofix (Beta)
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
Run ID: 82196bde-61fb-41d7-8d5f-b3b9cfd8b837
📒 Files selected for processing (2)
shepherd.js/src/step.tsshepherd.js/test/unit/step.spec.js
| if (isHTMLElement(this.el)) { | ||
| this.el.remove(); | ||
| this.el = null; | ||
| this.el = undefined; |
There was a problem hiding this comment.
Preserve getElement() contract while fixing the guard logic
Line 450 changes the destroyed sentinel to undefined, but getElement() docs/type still indicate destroyed steps return null. That silently changes external behavior. Prefer fixing the guard in _setupElements() to treat both null and undefined as “not mounted,” and keep teardown assigning null.
Suggested patch
diff --git a/shepherd.js/src/step.ts b/shepherd.js/src/step.ts
@@
- if (isHTMLElement(this.el)) {
- this.el.remove();
- this.el = undefined;
- }
+ if (isHTMLElement(this.el)) {
+ this.el.remove();
+ this.el = null;
+ }
@@
- if (!isUndefined(this.el)) {
+ if (this.el != null) {
this.destroy();
}🤖 Prompt for 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.
In `@shepherd.js/src/step.ts` at line 450, The teardown at line 450 assigns
`undefined` to this.el, but the getElement() method's contract and type
signature indicate it returns null for destroyed steps. Revert line 450 to
assign null instead of undefined to maintain the documented contract. Then
update the guard logic in _setupElements() to check if this.el is either null or
undefined (treating both as "not mounted") to handle any edge cases where
undefined might be present from other code paths.
Currently on function
_setupElementsof step, the destroy function is called ifthis.elis undefined but the destroy method setthis.elto null. So functiondestroyis called also on destroyed element which trigger unnecessary 'destroy' event.Another possible change would be to change the condition in
_setupElementsto check ifthis.elis either undefined or null.This is linked with reported issue #3443
Summary by CodeRabbit
Bug Fixes
Tests