question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught Errors on update={this.props.location.pathname}

See original GitHub issue

So some of the tours I’m using go through different pages. For example, I have a registration tour that guide the user on clicking on the “Sign up” button to go to the sign up page, and the tour continues on giving information about what to fill in 'till the “Submit” button.

I’ve set up the tour steps for the different paths and set update to this.props.location.pathname (update={this.props.location.pathname}). The issue I noticed when doing this is when the user is in, let’s say, step 5, and then changes page and the steps for that page have less than 5 steps, the steps update but the “current step number” doesn’t, so it tries to access steps[current] and it throws errors like this: image There are also other spots in the code that it tries to access steps[current] attributes without verifying if it exists. So I think it is something to look at for future versions.

For now, is there a way of reseting the current number everytime the steps update or something like this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kaelhemcommented, Jun 30, 2020

@elrumordelaluz Nice! Thanks for that. I didn’t think to use the goTo like this. Good catch. Also, for posterity, I’ve updated the sample to be able to re-open the ‘main’ tour (with the startAt parameter set to 0). Now, I’ve got an easy way to make a lot of tours for my app 😃

Edit: Even better, I’m using a little helper to avoid repeating the: props => <Step {...props}> on each steps. Like this:

const steps = definitions => definitions.map(def => ({
  ...def,
  content: props => React.cloneElement(def.content, { ...props })
}))

(And I’ve updated the previous codesandbox code).

0reactions
elrumordelaluzcommented, Jun 30, 2020

Hey @kaelhem thank you for creating and sharing a sandbox.

I solved this particular use case with the following approach: since the step.content could be a func I switched into it the content for steps of first and second sections, like this:

// ...
first: (Step, onLoadTourSection) => [
  {
    selector: "#bt1",
-   content: <Step>the first button</Step>
+   content: props => <Step {...props}>the first button</Step>
  },
  {
    selector: "#bt2",
-    content: <Step>the second button</Step>
+   content: props => <Step {...props}>the second button</Step>
  }
],
// ...

Then, use the prop.goTo inside the Step Component to go back to 0 when clicking the button. something like this:

- const Step = ({ children }) => (
+ const Step = ({ children, goTo }) => (
  <div>
    {currentSteps !== "main" && (
      <button
        style={{ position: "absolute", left: 5, top: 5 }}
        onClick={() => {
          onLoadTourSection("main");
+          goTo(0);
        }}
      >
        back
      </button>
    )}
    {children}
  </div>
);

Since the main section has only one step, going to the step 0 you are sure the Tour will found an element in the Array.

Here is the working example. Please, let me know if this approach makes sense for you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

props.location is undefined with route component
My question is why i can't take value of props.location.pathname and why its run two times and the second time it throw an...
Read more >
How to Handle Routing in a React Application using the React ...
This path prop is used to identify the portion of the URL that the router should match. If the view changes, it may...
Read more >
A Complete Guide to React Router: Everything You Need to ...
In this comprehensive, up-to-date tutorial, you'll learn everything you need to know to build production ready apps with React Router.
Read more >
Error Boundaries - React
Use componentDidCatch() to log error information. class ErrorBoundary extends React.Component { constructor(props) ...
Read more >
React Router v6 - Remix
Component { render() { return ( <Switch> <Route path="blog/:id" render={({ ... this.props; window.ga("set", "page", location.pathname + ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found