Skip to content
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

Merged
merged 3 commits into from
May 31, 2017

Conversation

mcsf
Copy link
Member

@mcsf mcsf commented May 17, 2017

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.

@mcsf mcsf added the Framework label May 17, 2017
@matticbot
Copy link
Contributor

@mcsf mcsf added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 17, 2017
@mcsf mcsf self-assigned this May 17, 2017
@mcsf mcsf requested review from gwwar and jblz May 17, 2017 21:17
@matticbot matticbot added the [Size] S Small sized issue label May 17, 2017
import { ROUTE_SET } from 'state/action-types';

const debug = debugFactory( 'calypso:restore-last-location' );
const key = 'last_path';
Copy link
Contributor

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`;

if ( ! hasInitialized ) {
hasInitialized = true;
}
localforage.getItem( key ).then( ( lastPath ) => {
Copy link
Contributor

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.

@matticbot matticbot added [Size] M Medium sized issue and removed [Size] S Small sized issue labels May 20, 2017
@mcsf
Copy link
Member Author

mcsf commented May 20, 2017

Thanks for the review, @gwwar! I've addressed your feedback and added guards against non-Calypso paths (p2-p58i-5Xi).

}

return next( action );
} );
Copy link
Contributor

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 ) );

mcsf added 3 commits May 30, 2017 13:52
- 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
@mcsf mcsf force-pushed the update/restore-last-location-localforage branch from 0c57981 to ce14f89 Compare May 30, 2017 13:01
@mcsf
Copy link
Member Author

mcsf commented May 30, 2017

@gwwar, feedback addressed. Might I get a :shipit:? :)

@mcsf mcsf changed the title restoreLastLocation: use localforage restoreLastLocation: use localforage, don't redir outside Calypso May 30, 2017
action.path === '/' &&
! isOutsideCalypso( lastPath ) ) {
debug( 'redir to', lastPath );
page( lastPath );
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@gwwar gwwar left a 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

@mcsf
Copy link
Member Author

mcsf commented May 30, 2017

Thanks for the review!

@mcsf mcsf added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 30, 2017
@mcsf mcsf merged commit 75c13bd into master May 31, 2017
@mcsf mcsf deleted the update/restore-last-location-localforage branch May 31, 2017 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework [Size] M Medium sized issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants