remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
29.65k stars 2.5k forks source link

Changing routes quickly sometimes leads to errors finding routes #7080

Closed kentcdodds closed 1 month ago

kentcdodds commented 1 year ago

What version of Remix are you using?

1.19.2

Are all your remix dependencies & dev-dependencies using the same version?

Steps to Reproduce

Got this from https://github.com/kentcdodds/kentcdodds.com/issues/473

  1. go to blog page
  2. Open useEffect vs useLayoutEffect article
  3. scroll down and open visit course link
  4. go back in browser history very quickly (click twice quickly on the go back button)
  5. you should find yourself in the blog page
  6. instead error appears

Expected Behavior

The /blog route should be shown

Actual Behavior

You get an error (I have an error boundary but it's not shown):

TypeError: Cannot read properties of undefined (reading 'links')
    at https://kentcdodds.com/build/_shared/chunk-NA3JZD7E.js:9:330
    at Array.map (<anonymous>)
    at _n (https://kentcdodds.com/build/_shared/chunk-NA3JZD7E.js:9:284)
    at https://kentcdodds.com/build/_shared/chunk-NA3JZD7E.js:14:2535
    at Object.useMemo (https://kentcdodds.com/build/_shared/chunk-Y6UZ2JHA.js:6:25719)
    at r.useMemo (https://kentcdodds.com/build/_shared/chunk-52ROR7N5.js:1:6137)
    at Qo (https://kentcdodds.com/build/_shared/chunk-NA3JZD7E.js:14:2523)
    at du (https://kentcdodds.com/build/_shared/chunk-Y6UZ2JHA.js:6:19466)
    at Ba (https://kentcdodds.com/build/_shared/chunk-Y6UZ2JHA.js:8:43659)
    at Ua (https://kentcdodds.com/build/_shared/chunk-Y6UZ2JHA.js:8:39459)

6 total relevant errors appear in the console image image

hichemfantar commented 1 year ago

I just wanted to mention that this doesn't always happen, even when quickly switching routes. It may be some kind of race condition.

brophdawg11 commented 1 year ago

@kentcdodds are you sure you're on 1.19.2? I'm seeing 1.17.1 in the sourcemaps and also in the preserved comments at the bottom of the bundles files: https://kentcdodds.com/build/_shared/chunk-NA3JZD7E.js

Screenshot 2023-08-21 at 4 11 47 PM Screenshot 2023-08-21 at 4 13 40 PM

This sounds like https://github.com/remix-run/remix/issues/1757 which was fixed in 1.18.0, so if you are on 1.17.1 this would make sense showing up on these fast back button navigations. The underlying issue is described in more detail here and the fix we went with was just trying to detect this URL mismatch and doing a browser reload.

kentcdodds commented 1 year ago

Oh man, I apologize for my lazy issue filing 🤦‍♂️ I can't remember my state of mind when I opened this issue, but I apologize for not double-checking that I was upgraded before opening this. Sorry for the wild goose chase. Thank you for fixing it!

I've just upgraded (thanks for npx upgrade-remix!!) and it's now extremely difficult to reproduce this issue. I have to hit forward/backward in random orders over and over again very rapidly to have it show up. I'm not sure what could be causing this, but like I said, it's very difficult to reproduce and users won't be behaving this way normally so I think this is safe to close, but I'll leave that to you.

brophdawg11 commented 1 year ago

Well drat - I wish "extremely difficult" was instead "impossible" 😂 , so I guess there's still some path that can hit it. I'll keep it open for now but won't put it high on the priority list since if it does happen a simple refresh oughta get the user back to a working state.

I have a small hope/hunch that https://github.com/remix-run/remix/pull/7133 might allow us to fix this in a better manner without the forced reload since we could rely on lazy to load the modules for the new URL - and just delay hydration. I'll loop back and see if that helps once we land that.

anthonymartinovic-eiq commented 10 months ago

Are there any updates for this issue? We're currently running on version 2.1.0 and are dealing with the same error for one particular route.

Unfortunately I've been unable to find a consistent way to reproduce this error, it's happening seemingly at random.

brophdawg11 commented 1 month ago

Please see details in https://github.com/remix-run/remix/issues/1757#issuecomment-2299585123 but we think this is no longer an issue in current versions of Remix so I'm going to close it out. Please re-open with reproduction steps if anyone comes across this again!