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

Update createBrowserHistory.js #100

Merged
merged 1 commit into from
Oct 15, 2015
Merged

Conversation

pwmckenna
Copy link
Contributor

add support for forceRefresh

addresses issue: #95

@taion
Copy link
Contributor

taion commented Oct 14, 2015

This actually isn't going to work if someone just calls createBrowserHistory(). Check how this is done on e.g. createHashHistory - we use a default value for options, and use destructuring to pull out the param:

https://github.com/rackt/history/blob/v1.12.5/modules/createHashHistory.js#L39
https://github.com/rackt/history/blob/v1.12.5/modules/createHashHistory.js#L45

@pwmckenna
Copy link
Contributor Author

@taion thanks for the hand holding...you guys clearly care about a gentle onboarding. much appreciated.

invariant(
canUseDOM,
'Browser history needs a DOM'
)

let isSupported = supportsHistory()
let { forceRefresh } = options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent here is inconsistent with the rest... should be 2 spaces rather than 3.

@taion
Copy link
Contributor

taion commented Oct 14, 2015

We should also document this somewhere.

@jlongster
Copy link
Contributor

I just tried this out, and there's still a bug. When the location changes, it still fires all listeners immediately. That means that I see the page "glitch" immediately for a second, until the window reload occurs and actually navigates to the new URL.

We need a way to tell history not to actually internally update its location if we are doing this. One way to do this is in transitionTo in createHistory.js, allow finishTransition to return a boolean value indicating if the location should actually be updated. It could return false to forcefully stop it, just like an onClick handler. The new code would look something like this:

      if (ok) {
        if(finishTransition(nextLocation) !== false) {
          updateLocation(nextLocation);
        }
      } else if (location && nextLocation.action === _Actions.POP) {
        ...
      }

I just tried this and it works.

@pwmckenna
Copy link
Contributor Author

@jlongster would you mind describing how you're manually testing. sorry if that sounds overly rudimentary.

@jlongster
Copy link
Contributor

@pwmckenna I just modified the react-router code in my project manually. If you're talking about which projects, I'm testing it on my blog: https://github.com/jlongster/blog

But it's probably not worth setting it up. Just try it on a simple project, and maybe delay the window.location.href = ... line by a second or so, and you'll see it.

@taion
Copy link
Contributor

taion commented Oct 14, 2015

@jlongster IMO that's a separate bug though? Would the same issue not arise if the History API were actually unavailable?

@jlongster
Copy link
Contributor

@taion That's true, yes it would have the same issue. Seems like we could still fix it in here though, unless you really want a separate PR?

@taion
Copy link
Contributor

taion commented Oct 14, 2015

I think it might be slightly nicer since it's a separate atomic thing that's orthogonal to this.

@jlongster
Copy link
Contributor

Ok done: #103. If accepted this should add return false after doing window.location.href = ...

@taion
Copy link
Contributor

taion commented Oct 14, 2015

I don't understand the test failure so I'm just blindly re-running the PR build. This looks good to me.

@taion
Copy link
Contributor

taion commented Oct 14, 2015

LGTM. Not sure what our policy for merging stuff is so I'll let someone else hit the green button 😄

@taion
Copy link
Contributor

taion commented Oct 14, 2015

@jlongster Sorry what I meant was that the return false part or whatever should also go in #103, since that's an orthogonal fix that also covers the existing case where HTML5 history is not supported. Just makes the diffs cleaner to read.

mjackson added a commit that referenced this pull request Oct 15, 2015
Update createBrowserHistory.js
@mjackson mjackson merged commit 90de43e into remix-run:master Oct 15, 2015
@mjackson
Copy link
Member

Looks great. Thanks, @pwmckenna!

@pwmckenna pwmckenna deleted the patch-1 branch October 24, 2015 16:27
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants