preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.02k stars 155 forks source link

Cannot read property 'forEach' of undefined on every route change #343

Closed lukepighetti closed 4 years ago

lukepighetti commented 4 years ago

I have a fairly underwhelming router setup

export default class App extends Component {
  render() {
    return (
      <Router>
        <HomeView path="/" data={require("../stubs/home.json")} />
        <Login
          path="/login"
          isLoggedIn={isLoggedIn}
          onLoginSuccess={() => route("/settings", true)}
          onLoginFailure={() => route("/", true)}
        />
        <Logout path="/logout" onLogoutSuccess={() => route("/", true)} />
        <SettingsView
          path="/settings"
          api={api}
          data={require("../stubs/settings.json")}
        />
      </Router>
    );
  }
}

And every time I navigate to a new route I get this error in latest Chrome.

Screen Shot 2019-11-03 at 5 13 20 PM

Break location

Screen Shot 2019-11-03 at 5 13 02 PM

The error + break seem to be very unhelpful. I'd love to provide more details but I'm not sure how to figure out more about what's going on. Any suggestions?

andrewiggins commented 4 years ago

Hey @lukepighetti Hmmm that is a weird error. What versions of preact and preact-router are you using? Are you using preact/compat or preact/hooks? The error reminds me of a bug we fixed in preact version 10.0.4. If you aren't using that version, could you try upgrading to that one?

Also, if you have a full repro you can share (e.g. in a codesandbox) that might help us narrow down the cause. I tried to build one here but it didn't repro :/

marvinhagemeister commented 4 years ago

Another shot in the dark: Maybe you're have a wrong import somewhere like preact/hooks/src instead of preact/hooks.

lukepighetti commented 4 years ago

Upgraded to 10.0.4 and it appears to have been resolved. Will reopen if I run into it again. Thank you.