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

Fix infinite loops in compare page #639

Merged
merged 6 commits into from May 2, 2019
Merged

Fix infinite loops in compare page #639

merged 6 commits into from May 2, 2019

Conversation

willdurand
Copy link
Member

@willdurand willdurand commented Apr 24, 2019

Fixes #638
Fixes #628


While the code looked nice and the test suite was covering all the branches, it appears that most of the code was not needed because loading a file from the URL is done by fetchDiff, which takes an optional path. Given that there is no URL update triggered by our code, the URL stayed the same and everything just worked as intended. This was nice but complicated and not needed, so I removed it.

The fix for the infinite loop is mostly in src/reducers/versions.tsx. Because we load a file, we should abort this action too in case of an error. This allows the loadData() method to check the status of the version prop.

I added some commits to fix #628 too. I believe it works (i.e. I cannot trigger an infinite loop) but the UI sometimes lags. I covered the following scenarios:

I think protecting the thunk with a loading flag would help. I've done that in the last commit.

@codecov-io
Copy link

codecov-io commented Apr 24, 2019

Codecov Report

Merging #639 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #639      +/-   ##
==========================================
+ Coverage   98.42%   98.43%   +0.01%     
==========================================
  Files          45       45              
  Lines        1267     1279      +12     
  Branches      292      292              
==========================================
+ Hits         1247     1259      +12     
  Misses         19       19              
  Partials        1        1
Impacted Files Coverage Δ
src/reducers/versions.tsx 100% <100%> (ø) ⬆️
src/pages/Compare/index.tsx 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ec042c...fdcc3ed. Read the comment docs.

@willdurand willdurand force-pushed the fix-compare branch 2 times, most recently from 35361dc to ef965d2 Compare April 24, 2019 12:58
@willdurand
Copy link
Member Author

Looks like codecov did not update the coverage report according to the last pushed code...

@kumar303
Copy link
Contributor

Just so I don't forget what I said about this on IRC 😀 could you look into #628 first? Your patch here seems to be making it worse. I do like how you simplified the initial path loading, though. We should definitely do that.

@willdurand willdurand changed the title Fix infinite loop in compare page Fix infinite loops in compare page Apr 24, 2019
@willdurand
Copy link
Member Author

willdurand commented Apr 24, 2019

@kumar303 could you please test this patch? I am not sure if I am the only one seeing UI lags (cf. PR description). It looks like it ends up in the correct state though, but it takes time...

@willdurand willdurand changed the title Fix infinite loops in compare page [WIP] Fix infinite loops in compare page Apr 24, 2019
@willdurand willdurand changed the title [WIP] Fix infinite loops in compare page Fix infinite loops in compare page Apr 25, 2019
@willdurand
Copy link
Member Author

@kumar303 could you please test this patch? I am not sure if I am the only one seeing UI lags (cf. PR description). It looks like it ends up in the correct state though, but it takes time...

I've fixed this a bit by protecting the fetchDiff thunk with a loading flag, but the file tree still flickers a bit when we hit k too rapidly. I believe this is a separate issue, though.

@kumar303
Copy link
Contributor

...the file tree still flickers a bit when we hit k too rapidly. I believe this is a separate issue, though.

Can you file an issue for it? It's because the thunk is loading in the background for each file / diff you traverse. The flicker happens when one of the older diffs finally loads but a newer one loads right after it. I think this means we need debouncing. It may not be trivial to add debouncing.

@willdurand
Copy link
Member Author

willdurand commented Apr 25, 2019

Can you file an issue for it?

Yes. Edit: #644

It's because the thunk is loading in the background for each file / diff you traverse. The flicker happens when one of the older diffs finally loads but a newer one loads right after it. I think this means we need debouncing. It may not be trivial to add debouncing.

Maybe we could debounce the keyboard navigation component instead (the key listener maybe?).

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

This is way simpler, I like it!

It works great, I've just requested some fixes to the tests.

src/reducers/versions.tsx Outdated Show resolved Hide resolved
src/pages/Compare/index.spec.tsx Outdated Show resolved Hide resolved
src/pages/Compare/index.spec.tsx Show resolved Hide resolved
src/reducers/versions.spec.tsx Outdated Show resolved Hide resolved
src/reducers/versions.spec.tsx Outdated Show resolved Hide resolved
src/reducers/versions.spec.tsx Show resolved Hide resolved
src/reducers/versions.spec.tsx Outdated Show resolved Hide resolved
src/reducers/versions.spec.tsx Show resolved Hide resolved
src/reducers/versions.tsx Show resolved Hide resolved
@willdurand
Copy link
Member Author

Thanks @kumar303, I believe I addressed all the change requests. There is one for which I could not do anything.

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

This is great :shipit:

@willdurand willdurand merged commit e407f89 into master May 2, 2019
@willdurand willdurand deleted the fix-compare branch May 2, 2019 09:04
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.

Infinite loop in Compare page Infinite loop when quickly switching files in compare view
3 participants