-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
restoreLastLocation: use localforage, don't redir outside Calypso #14196
Conversation
client/state/routing/middleware.js
Outdated
import { ROUTE_SET } from 'state/action-types'; | ||
|
||
const debug = debugFactory( 'calypso:restore-last-location' ); | ||
const key = 'last_path'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
const LAST_PATH = 'last_path`;
client/state/routing/middleware.js
Outdated
if ( ! hasInitialized ) { | ||
hasInitialized = true; | ||
} | ||
localforage.getItem( key ).then( ( lastPath ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is async, we're calling next( action )
before we can call page
. It's somewhat minor, but this currently updates the behavior to show a flash of /
before we're redirected to another place.
Thanks for the review, @gwwar! I've addressed your feedback and added guards against non-Calypso paths (p2-p58i-5Xi). |
client/state/routing/middleware.js
Outdated
} | ||
|
||
return next( action ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unlikely, but sometimes the gets can fail. Let's also make sure we call next( action )
when that happens.
localforage.getItem( LAST_PATH ).then( redirectToLastPath, () => { return next( action ) );
- Don't save from or redirect to a path that isn't relative to Calypso. - Don't call `next` before `page` - Move `hasInitialized` state one function down to make it a store global instead of a module global
0c57981
to
ce14f89
Compare
@gwwar, feedback addressed. Might I get a |
action.path === '/' && | ||
! isOutsideCalypso( lastPath ) ) { | ||
debug( 'redir to', lastPath ); | ||
page( lastPath ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still seeing a flash of the reader. Perhaps we need to return early here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. I think we'll play with this in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the note I left, the behavior here looks good
Thanks for the review! |
Refinement of #14070 as suggested by @gwwar (#)
Testing
Same instructions as #14070; behavior preserved, save for the improvement that the a user should never be redirected from
/
to somewhere external to Calypso.