remix icon indicating copy to clipboard operation
remix copied to clipboard

Unexpected transition in action redirects

Open rphlmr opened this issue 2 years ago • 3 comments

What version of Remix are you using?

1.7.5

Steps to Reproduce

I made a repro, with a record ;)

https://github.com/rphlmr/unexpected-transition-in-action-redirects

Given these 3 routes: / /form/index /form/end

/form/index

  • view => a Form posting to the action
  • loader => read a session cookie and returns a value for the form input default value
  • action => save form data in a session and redirects to /form/end

/form/end

  • view => a Form to review previous data and "save it"
  • loader => read a session cookie if exists. If it not exists, throw redirect to /. It intends to prevent "back" action from the user after the final submission.
  • action => destroy the session and redirect to / (this is the final submission)

Steps to reproduce : Open developer tools > console Complete the Form and be redirected to / Try to click the browser's back button You should see the error

Expected Behavior

Imagine that's a form wizard with multiple steps. The last step intends to have all the previous step's data and do something with it. Going back here after the final submission is not expected and the user should be redirected somewhere.

Actual Behavior

The user is not going back to the previous page, but, he's not redirected either (he stays where he was when clicking the browser's back button).

The console print an error (client side) :

invariant.js:13 Uncaught (in promise) Error: Unexpected transition: {"state":"loading","type":"normalLoad","location":{"pathname":"/form/end","search":"","hash":"","state":{"isRedirect":true,"type":"action","setCookie":true},"key":"ctl1qec9"}}
    at invariant2 (invariant.js:13:11)
    at handleActionRedirect (transition.js:778:5)
    at Object.send (transition.js:182:19)
    at components.js:97:23
    at commitHookEffectListMount (react-dom.development.js:23150:26)
    at commitPassiveMountOnFiber (react-dom.development.js:24926:13)
    at commitPassiveMountEffects_complete (react-dom.development.js:24891:9)
    at commitPassiveMountEffects_begin (react-dom.development.js:24878:7)
    at commitPassiveMountEffects (react-dom.development.js:24866:3)
    at flushPassiveEffectsImpl (react-dom.development.js:27039:3)

Discord discussion : https://discord.com/channels/770287896669978684/1022864309170221086

rphlmr avatar Nov 15 '22 11:11 rphlmr

Any news about this ?

MaximeGratens avatar Jan 06 '23 18:01 MaximeGratens

Sentry reports me the same error but can't reproduce

jorisre avatar Jan 08 '23 15:01 jorisre

Yes same as me

MaximeGratens avatar Jan 09 '23 16:01 MaximeGratens

Seeing a lot of these errors in Sentry but am unable to reproduce it myself

liegeandlief avatar Apr 03 '23 15:04 liegeandlief

I wasn't able to reproduce this locally with the linked repo on 1.7.5, and everything also seems fine on 1.16.0 with useNavigation. Since we've completely re-written the internal routing logic in @remix-run/router and this invariant no longer exists I'm going to close this out. Please re-open with a reproduction if you are still seeing this issue.

brophdawg11 avatar May 05 '23 16:05 brophdawg11