HiDeoo / intro.js-react

Intro.js react wrapper
MIT License
395 stars 58 forks source link

stepIndex values differ between Windows and Apple-based devices at the end of the tour. #88

Closed hiroshinishio closed 1 year ago

hiroshinishio commented 1 year ago

Describe the bug

stepIndex values differ between Windows and Apple-based devices at the end of the tour. So I had to do this workaround.

  const onExit = async (stepIndex: number) => {
    // It should be compared to steps.length -1, but at least in Windows, there is a weird quirk in the way the library counts indexes, so when there are n steps, the index just before Exit is somehow n.
    // In iOS, like Mac PC, iPad, and iPhone, stepIndex will be 'n - 1'.
    if (stepIndex === steps.length || stepIndex === steps.length - 1) {
      setStepEnabled(false);
      // Process that counts once the tour is completed to the end.
      const newNumberOfTimesCompleted = numberOfTimesCompleted + 1;
      setNumberOfTimesCompleted(newNumberOfTimesCompleted);
      await handleSubmitProductTour(
        docId,
        productTourName,
        newNumberOfTimesCompleted
      );
    }
  };

To Reproduce

To reproduce, prepare a Windows PC and a Mac PC (or iPad or iPhone) and try console logging stepIndex in the onExit function.

I was able to notice this because my fellow developer and I were using different operating systems. I don't think I would have noticed otherwise.

Expected behavior

I would like to see the same count for devices or rather operating systems.

How often does this bug happen?

Every time

System Info

PC Spec

Device

OS

Browser

Mobile Spec

Device and OS

Browser

Additional Context

I don't know if it is because of Intro.js-react or Intro.js. So created the same issue for Intro.js too. https://github.com/usablica/intro.js/issues/1746

HiDeoo commented 1 year ago

Thanks for the very detailed issue. This is definitely a weird one.

I think intro.js by default, at least according to the documentation, does not provide the step index to the exit callback. This may have been something I added because I needed it at the time but it looks like I'm not doing anything fancy with it, I just call the callback with the _currentStep provided by the intro.js instance:

https://github.com/HiDeoo/intro.js-react/blob/main/src/components/Steps/index.js#L116

I just tried to repro the issue using the small demo I have for this repository but was unable to repro, I always get on exit step index 1 logged on macOS Monterey & Windows 10.

Would you be able to try it and see if you can repro on your end using this demo? https://codesandbox.io/s/citpdf

If not, would you be able to provide a repro of the issue?

HiDeoo commented 1 year ago

If you're still having this issue, feel free to re-open with a small repro example.