bootstrap-tour icon indicating copy to clipboard operation
bootstrap-tour copied to clipboard

error thrown when right arrow pressed before tour started

Open nhouse opened this issue 9 years ago • 3 comments

If I create a tour and call tour.init();, pressing the right arrow key results in the following error being thrown in Chrome:

Uncaught TypeError: Cannot read property 'onNext' of undefined

Referring to the following line in e.prototype._showNextStep:

h = this._makePromise(g.onNext != null ? g.onNext(this) : void 0);

If I start the tour by calling tour.start() or tour.restart() before pressing the right arrow (even if ending the tour before pressing the right arrow), no error is thrown.

nhouse avatar Apr 15 '15 20:04 nhouse

+1

danielsedlacek avatar Mar 13 '17 14:03 danielsedlacek

I was able to resolve this in my local file by modifying the Tour.prototype._showNextStep method to add a check for undefined "step" value around line 443 of bootstrap-tour.js:

Tour.prototype._showNextStep = function() {
  var promise, showNextStepHelper, step;
  step = this.getStep(this._current);
  showNextStepHelper = (function(_this) {
    return function(e) {
      return _this.showStep(step.next);
    };
  })(this);
  if(typeof step === "undefined") {
    return;
  }
  promise = this._makePromise(step.onNext != null ? step.onNext(this) : void 0);
  return this._callOnPromiseDone(promise, showNextStepHelper);
};

bennettstone avatar Aug 10 '19 18:08 bennettstone

@bennettstone

I did the same thing locally.

FWIW you don't need to use typeof here.

This kind of check is useful if you're not sure if the variable exists. In this case you know it exists (it was assigned something a few lines above and there is no chance the step = ... line of code didn't execute if we've reached the if(typeof... line.)

All you want to know is whether the value of that variable equals undefined.

You can change that if statement to if (step === undefined) (Note the lack of quotes around undefined.

Then you'll be checking a known variable for the value undefined.

saintsGrad15 avatar Sep 26 '19 14:09 saintsGrad15