Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Feature/ switch explorer rendering to use react-virtualized #2182

Merged
merged 45 commits into from
Sep 1, 2018

Conversation

akinsho
Copy link
Member

@akinsho akinsho commented May 7, 2018

An issue I noticed with the explorer was that on reaching the lowest boundaries of the visible files/folders the scroll position would flicker on each move downwards making it hard/impossible to move to files which are out of view.

Having attempted to use/tweak the scrollIfNeeded function with no luck I've refactored the explorer to use react-virtualized instead which I believe was mentioned at some point was an eventual change we wanted to make, which has the added bonus of providing methods that can be used to control scrolling to selected elements.

This change also sets up the searchInExplorer functionality I'm planning by allowing for programmatically focusing search of a particular element.

Also due to ongoing difficulties identifying dom nodes as styled-components uses hashed classnames I've also added the typescript version of babel-plugin-styled-components which generates more readable classnames e.g. NodeWrapper-asdfsfs2324 rather than sc-dfaffr3242

Todo:

  • fix scroll issues when folder(s) is/are expanded - FIXED
  • text new file/folder input rendering error

@akinsho akinsho changed the title [WIP] Switch explorer rendering to use react-virtualised Switch explorer rendering to use react-virtualised May 7, 2018
@akinsho akinsho changed the title Switch explorer rendering to use react-virtualised Switch explorer rendering to use react-virtualized May 7, 2018
@codecov
Copy link

codecov bot commented May 7, 2018

Codecov Report

Merging #2182 into master will decrease coverage by 0.03%.
The diff coverage is 50.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2182      +/-   ##
==========================================
- Coverage   44.51%   44.48%   -0.04%     
==========================================
  Files         351      351              
  Lines       14302    14318      +16     
  Branches     1865     1863       -2     
==========================================
+ Hits         6367     6369       +2     
- Misses       7709     7723      +14     
  Partials      226      226
Impacted Files Coverage Δ
browser/src/UI/components/common.ts 92.85% <ø> (ø) ⬆️
browser/src/Services/DragAndDrop.tsx 39.13% <ø> (ø) ⬆️
...owser/src/Services/Sidebar/SidebarContentSplit.tsx 31.57% <ø> (ø) ⬆️
browser/src/Services/Explorer/ExplorerSplit.tsx 23.68% <0%> (ø) ⬆️
browser/src/UI/components/VimNavigator.tsx 73.07% <100%> (+1.07%) ⬆️
browser/src/Services/Explorer/ExplorerView.tsx 54.54% <50%> (-5.46%) ⬇️
browser/src/UI/components/SidebarItemView.tsx 56.25% <50%> (-10.42%) ⬇️

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 5beff5f...fa30106. Read the comment docs.

@akinsho akinsho changed the title Switch explorer rendering to use react-virtualized Feature/ switch explorer rendering to use react-virtualized May 8, 2018

switch (true) {
case renameInProgress:
return 35
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, how do we determine these sizes? I'm wondering if they are dependent on the ui.fontSize setting? I'm just worried about a bug where different font sizes cause rendering quirks.

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 actually fiddled with the sizes here and tbh the css with virtualized involved is more or less opaque to me but I didn't notice a big difference using the values which were trial and error as a result of that process, I've tweaked it however to use ui.fontSize to derive the size in case

</div>
<ExplorerContainer className="explorer">
<AutoSizer>
{({ height, width }) => (
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Thanks for wiring this all up 👍

@bryphe
Copy link
Member

bryphe commented May 9, 2018

An issue I noticed with the explorer was that on reaching the lowest boundaries of the visible files/folders the scroll position would flicker on each move downwards making it hard/impossible to move to files which are out of view.

Ah ya, I hit this too - didn't get a chance to log an issue, but it definitely was a problem! Thanks so much for fixing it!

Having attempted to use/tweak the scrollIfNeeded function with no luck I've refactored the explorer to use react-virtualized instead which I believe was mentioned at some point was an eventual change we wanted to make, which has the added bonus of providing methods that can be used to control scrolling to selected elements.

Awesome!! 💯 Thanks for going to those lengths to fix it. This will be much better long-term too, especially for large directories with tons of files - we only have to render whats on the screen.

This change also sets up the searchInExplorer functionality I'm planning by allowing for programmatically focusing search of a particular element.

Can't wait! 😄

Overall the change looks great! I had one small concern around how we calculate the row heights - I'm not sure how it works with different font sizes, so I wanted to see what you thought there.

Thanks @Akin909 !

@akinsho akinsho mentioned this pull request May 19, 2018
5 tasks
@akinsho
Copy link
Member Author

akinsho commented May 19, 2018

@bryphe made the changes you suggested re row height 👍 hopefully this is good to go

EDIT: Seems to be an issue with caching on appveyor.. not sure how to resolve that but they don't seem related to these changes.

const isSelected = id === selectedId

const PADDING = 10
const fontSize = parseInt(this.props.fontSize, 10)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I wonder if this handles the various cases we allow for fontsize? For example, it looks like 11px, 11pt, 11em would all get handled the same way here, but they would actually have very different pixel sizes. I think what we'd want instead is the measured font size, or some more deterministic way to get the size of the cells.


switch (true) {
case renameInProgress:
return rowSize * 1.5
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit concerned about these magic numbers here - 1.5 and 2.8. If someone changes the styling of the node or the creation, they might not realize they need to update these here, and get difficult to find bugs. Along the lines of the above comment - is there a more deterministic way we can get these sizes?

@akinsho
Copy link
Member Author

akinsho commented Aug 21, 2018

@CrossR could you give this PR a try/review especially re creating and renaming and moving files, I've kind of lost perspective on it think its a big improvement (re. the stutter) and havent noted any bugs today but previously noted a resizing issue which seems to have resolved itself.....

@akinsho akinsho changed the title [WIP] Feature/ switch explorer rendering to use react-virtualized Feature/ switch explorer rendering to use react-virtualized Aug 21, 2018
@keforbes
Copy link
Collaborator

Hey @Akin909, it looks like this PR has a branch conflict now. Can you take a look?

@CrossR CrossR self-requested a review August 24, 2018 15:52
@CrossR
Copy link
Member

CrossR commented Aug 30, 2018

I'm still getting some weirdness with the scroll sticking to the bottom.

If I scroll past the bottom of the menu, the bar sticks to the bottom for the entire time now. There is also some jumping still where the bar vanishes for a bit and then reappears after letting go of the scroll button.

Another thing I've noticed is that on inserting items sometimes the spacing is off.
Repro:

  • Open Oni with Oni repo.
  • Ctrl-h to highlight explorer,
  • G to move to bottom,
  • Ctrl-e to make a new file, and set name to a.txt.
  • New file is added fine, but weird spacing occurs:

image

Its up to you if you want to sort them in this PR or in a follow up, neither are as bad as the flickering, so I'd understand getting this in and sorting the bugs later(in a smaller more contained PR).

Let me know and if you decide on that, I can approve the PR. No point doing that now since there is a merge conflict.

use more thorough method for checking if props changed
simplify sidebar items components
switch to invalidating the cache if yanking, pasting etc occur
@akinsho
Copy link
Member Author

akinsho commented Aug 31, 2018

@CrossR thanks for having another look was reeeeeally stuck with the bug you noticed with the spacing I've switched the strategy to a more brute force one instead of only trying to update the affected nodes when something like a rename etc happens I instead now trigger a redraw/update of all the visible nodes so should avoid random ones here or there not being measured properly.

Re holding the button and the bar disappearing when is that happening? I haven't noted it since I switched to having the bar stick on the bottom although, one of the limitations of using virtualized and the cellMeasurer component from the docs is

Since this component measures one cell at a time to determine it's width/height, it will likely be slow if a user skips many rows (or columns) at once by scrolling with a scrollbar or via a scroll-to-cell prop. There is (unfortunately) no workaround for this performance limitation at the moment.

So without finding a faster library or a different implementation button mashing could always lead to this although I there might be little ways to optimise this or hide it at least. Although the library authors have been talking about a new version for a while now so we'll see.

Anyway if you get a moment can you try it again to see if the weird spacing bug is still there(locally I havent noted it anymore), I never found a consistent way to reproduce it (your repro doesnt always bring it on nor have I found it to consistently reproduce)

@CrossR
Copy link
Member

CrossR commented Sep 1, 2018

Re holding the button and the bar disappearing when is that happening? I haven't noted it since I switched to having the bar stick on the bottom although, one of the limitations of using virtualized and the cellMeasurer component from the docs is

Seems to still happen when I scroll rapidly in the Oni repo:

gif

I can't seem to repro the other bug now though, and I tried 10-15 times whereas before it was happening maybe every 2/3 times I tried.

@akinsho
Copy link
Member Author

akinsho commented Sep 1, 2018

@CrossR thanks for the GIF that helps a lot 💯 , re that issue it relates to the quote above re performance and the strategy were using basically the library cant keep up with the holding the button

As far as the docs say there is no clear way round it I'm hoping future releases improve performance and we get a fix for free if not down the line we might have to switch to a different strategy I have no idea what, the main value of the library is for scrolling v. long lists not quite what were doing which is scrolling to indexes very fast using keyboard input

@akinsho
Copy link
Member Author

akinsho commented Sep 1, 2018

Since it seems the really annoying bug is no longer reproducible (I haven't encountered it again locally) I'd like to close this PR off and finally delete the branch 😆

Copy link
Member

@CrossR CrossR left a comment

Choose a reason for hiding this comment

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

Code changes look good, and the explorer is a lot more solid now!

Is it worth documenting the bugs in issues so they aren't forgotten?

@akinsho
Copy link
Member Author

akinsho commented Sep 1, 2018

@CrossR thanks for the approval (again 👍)

@akinsho akinsho merged commit c06df64 into onivim:master Sep 1, 2018
@akinsho akinsho deleted the bugfix/fix-flickering-scroll-explorer branch September 1, 2018 21:24
@akinsho akinsho restored the bugfix/fix-flickering-scroll-explorer branch October 1, 2018 09:35
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