Skip to content

Fix issue 386 #395

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

Merged
merged 5 commits into from
Mar 10, 2020
Merged

Fix issue 386 #395

merged 5 commits into from
Mar 10, 2020

Conversation

jonasjabari
Copy link
Member

Issue #386: page transition is broken when using browser back button

Changes

  • added spec to reproduce the issue
  • changed navigation condition which was introduced in Fix Anchor Link triggers transition #361
  • the condition in Fix Anchor Link triggers transition #361 tried to check previous and target location, but was never able to read the previous state (not possible in popstate, as far as I learned)
  • I added the previous state (initial and right before any transition) to the store
  • now it's possible to compare previous and target state in the onpopstate event

@jonasjabari jonasjabari requested a review from PragTob March 9, 2020 15:12
@jonasjabari
Copy link
Member Author

I'm targeting this PR to master as I want to release the bug fix directly as a hot fix. will be released as 0.7.4.1 then

@PragTob
Copy link
Collaborator

PragTob commented Mar 10, 2020

@jonasjabari if it is in master, how will you backport it to dev? The more normal strategy (that I'm used to) is merge it to develop, then cherry pick and adapt it for the release branch support.

0.7.4.1 is also rather uncommon, the only project I know of that uses that (sometimes) is JRuby due to their 9k joke/versioning. It'd be more common to release 0.7.5 aka just increase the patch elvel.

Copy link
Collaborator

@PragTob PragTob left a comment

Choose a reason for hiding this comment

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

Sorry for introducing the issue 😅

Added minor comments about the implementation and potentially flaky spec.

IMG_20171225_091935

if (isNavigatingToAnotherPage(document.location, event)) {
this.$store.dispatch("navigateTo", {url: document.location.pathname, backwards: true} );
};
let needToNavigate = self.currentPathName !== document.location.pathname ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

the intent behind extracting it to a separate file was to encapsulate the logic, make it independently testable in JS unit tests and not muddy the app.js with these implementation details. I'd still pefer that personally, otherwise I'd vote for a private function to take care of this as I think the implementation detail here makes it harder to read this function/see what it's actually doing. But that's arguably style (aka my style is small intention revealing functions that point you to the detail)

Copy link
Member Author

Choose a reason for hiding this comment

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

changed that to your approach ;)

expect(page).to have_content("This is Page 2")
expect(page).to have_selector("body.not-reloaded")

# page.evaluate_script('window.history.back()')
Copy link
Collaborator

Choose a reason for hiding this comment

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

please delete outcommented code :)

Copy link
Member Author

Choose a reason for hiding this comment

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

oh yes!

page.go_back

element = page.find("#my-div-on-page-1")
refreshed_content_on_page_1 = element.text
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is prone to a race condition again. if page.go_back needs longer than finding the div then it might end up with the old content. You can fix this with expect(page).to have_no_content(first_content_on_page_1) (expect(page).not_to have_content... also works due to dark rspec magic) instead of expect(first_content_on_page_1).not_to eq(refreshed_content_on_page_1)

Copy link
Member Author

Choose a reason for hiding this comment

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

good call!

@@ -10,12 +9,20 @@ const componentDef = {
},
computed: Vuex.mapState({
asyncTemplate: state => state.pageTemplate,
currentPathName: state => state.currentPathName,
currentSearch: state => state.currentSearch,
currentOrigin: state => state.currentOrigin,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused that we'd need this. Yes, I read your comment it seems weird to me that there should be no way to access that state throughout the history/event API etc. 🤔

And I mean I also tried it out (not with the back button though obviously 😅 ) and there I had it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmkay, seems more involved. Odd, I guess I have to read up on the history APIs etc. https://stackoverflow.com/questions/8980255/how-do-i-retrieve-if-the-popstate-event-comes-from-back-or-forward-actions-with

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried a lot, but this was the only way to fix it.

@jonasjabari jonasjabari changed the base branch from master to develop March 10, 2020 10:05
@jonasjabari jonasjabari changed the title Hot-Fix issue 386 Fix issue 386 Mar 10, 2020
@jonasjabari
Copy link
Member Author

@jonasjabari if it is in master, how will you backport it to dev? The more normal strategy (that I'm used to) is merge it to develop, then cherry pick and adapt it for the release branch support.

0.7.4.1 is also rather uncommon, the only project I know of that uses that (sometimes) is JRuby due to their 9k joke/versioning. It'd be more common to release 0.7.5 aka just increase the patch elvel.

I change target branch to develop and will release 0.7.5 together with some minor changes on the current develop branch. I think that is indeed cleaner :)

Copy link
Collaborator

@PragTob PragTob left a comment

Choose a reason for hiding this comment

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

Looking good, small design idea 👌

IMG_20170723_143434

if (isNavigatingToAnotherPage({
origin: self.currentOrigin,
pathName: self.currentPathName,
search: self.currentSearch
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small thing, having all these "flat" in the store seemed weird to me before. This makes me feel it's even weirder. How about storing them in an object in the store? Like: currentLocation: {all_da_values} then that object could be passed on as a whole. It also makes it clearer that all these values belong together and are not of too much use on their own.

@jonasjabari jonasjabari merged commit 6586691 into develop Mar 10, 2020
@PragTob PragTob deleted the fix_issue_386 branch March 10, 2020 10:46
@jonasjabari jonasjabari added this to the 0.7.5 milestone Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants