nteract / hydrogen

:atom: Run code interactively, inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor.
https://nteract.gitbooks.io/hydrogen/
MIT License
3.93k stars 333 forks source link

Result views lose scroll position when off-screen #785

Open nikitakit opened 7 years ago

nikitakit commented 7 years ago

I've been having some odd interactions with result bubbles lately, and I've finally isolated some concrete cases of weird behavior that relate to result bubbles being un-rendered when they are no longer on the screen.

I'm consolidating two different behaviors here because I think they're related. Note that I am on older versions of Atom/Hydrogen at the moment, so there's a chance these issues have already been fixed.

1. Lost scrolling

The first is that scrolling location is lost when a result bubble is moved offscreen. To reproduce, run some code such as:

for i in range(1000):
    print(i)

# %%

# [several screens worth of newlines here]

First scroll the result bubble down so it displays numbers in the 900s. Then scroll the main window down until the result bubble is offscreen by at least a dozen lines. Then scroll back to the top. The result bubble will now have the scrolling undone.

2. Result bubbles vanishing -> fixed upstream

For the second issue, I can reproduce with the following code:

# %%
for i in range(1000):
    print(i)

# %%
# [scroll so this line is the first line on screen]
for i in range(1000):
    print(i)

First run both cells, and scroll the window such that the marked line is the topmost line visible. Then switch to another tab and back. What I see in this case is that the second result bubble vanishes entirely (but scrolling the window will bring it back).

buyology commented 7 years ago

I guess this has to do with the fact that Atom removes the decorator from the DOM as you scroll down and adds it back in and the scrollTop-state is lost?

Wonder if this needs to be fixed upstream in Atom (they do keep some registry of these components?) or if we could store this property somehow as it's removed and restore it upon recreation

lgeiger commented 7 years ago

I can definitely reproduce this on latest master as well.

I agree with @buyology, this might be a problem in Atom core. They probably do some fancy stuff to improve performance.

buyology commented 7 years ago

Spent some time looking at this and from what I could see this clearly had something to do when they first remove it from the DOM and add it back in.

I even tried to pull in https://github.com/atom/atom/pull/13880 as this is supposed to alter these things, and off-screen-block-decorations-component has been removed, but I guess that behaviour's just been moved somewhere else

It'd be very nice if Atom had an event when they added the component back in, then at least we could store the scrollTop and add it back in

BenRussert commented 7 years ago

I see the lost scrolling issue when switching between tabs and think this is most likely a little bug in hydrogen.

I am not sure if I see the result bubble vanishing problem (though I feel like I have before so perhaps this was fixed upstream).

lgeiger commented 7 years ago

Just a quick update on this. Problem 2 was fixed upstream and isn't reproducible on 1.20.0-beta7 (probably 1.19.7 too) anymore.

Unfortunately problem 1 is still present.