Skip to content

feat(docs-infra): add debouncing in storing scroll position - #28368

Closed
wKoza wants to merge 4 commits into
angular:masterfrom
wKoza:improve_save_scroll
Closed

wKoza wants to merge 4 commits into
angular:masterfrom
wKoza:improve_save_scroll

Conversation

@wKoza

@wKoza wKoza commented Jan 25, 2019 •

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #28332

There is no debouncing when we store the scroll Position;
Chrome seems not happy with that:
We have a message in the console after a while:

Throttling history state changes to prevent the browser from hanging.

FYI : https://bugs.chromium.org/p/chromium/issues/detail?id=786211
https://codereview.chromium.org/2972073002/#ps1

// TODO(crbug.com/394296): This is not the long-term fix to IPC flooding that we
// need. However, it does mitigate the immediate concern of \|pushState\| DoS
// (assuming the renderer has not been compromised).
bool History::IsHostFloodingPushState(const String& hostname) const {
const int kHostPushStateLimit = 50;
const HostLimit& current = host_limits.at(hostname);
 if (current.first > kHostPushStateLimit) {
    const double kHostPushStateLimitResetSeconds = 10.0;
    double now = MonotonicallyIncreasingTime();
    if (now - current.second > kHostPushStateLimitResetSeconds) {
      host_limits.Set(hostname, HostLimit{0, now});
    }
    return true;
  }

  host_limits.Set(hostname, HostLimit{current.first + 1, current.second});
  return false;
}

What is the new behavior?

  • There is now a debouncing before we store the scroll Position;
  • Remove unnecessary(?) try/catch block
  • Avoid a race-condition with navigating forward/back and immediately reloading

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@wKoza
wKoza requested a review from a team January 25, 2019 15:06
@wKoza
wKoza force-pushed the improve_save_scroll branch 2 times, most recently from 8e6850d to e087ce5 Compare January 25, 2019 16:41
@wKoza wKoza changed the title WIP feat(docs-infra): add debouncing in storing scroll position feat(docs-infra): add debouncing in storing scroll position Jan 25, 2019

@gkalpak gkalpak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thx, @wKoza ✨

Comment thread aio/src/app/shared/scroll.service.ts Resolved
@ngbot ngbot Bot added this to the needsTriage milestone Jan 25, 2019
@petebacondarwin petebacondarwin added type: bug/fix action: review The PR is still awaiting reviews from at least one requested reviewer comp: docs-infra labels Jan 25, 2019
@wKoza
wKoza force-pushed the improve_save_scroll branch from 7982e5e to c28b22c Compare January 25, 2019 20:27
Comment thread aio/src/app/shared/scroll.service.ts Resolved
Comment thread aio/src/app/shared/scroll.service.ts Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think with the code, a throw is unlikely.

@wKoza

wKoza commented Jan 26, 2019

Copy link
Copy Markdown
Contributor Author

@gkalpak , I have pushed three commits for the three fix/feat in order to help you with your reviews.

Comment thread aio/src/app/shared/scroll.service.ts Resolved
@wKoza

wKoza commented Jan 26, 2019

Copy link
Copy Markdown
Contributor Author

The CI throws an error that is not in relation to this PR.

Comment thread aio/src/app/shared/scroll.service.ts Resolved

@IgorMinar IgorMinar left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't we be using throttleTime instead of debounceTime?

We want the scroll position to be stored as one scrolls, but not too frequently. We don't want to delay scroll position updates until one stops scrolling + 500ms.

@wKoza

wKoza commented Jan 27, 2019

Copy link
Copy Markdown
Contributor Author

I've tested a throttle, even with a duration of 300ms, but the result isn't optimal. We lose, often, the exact last positon before the navigation. With a duration of 500ms, it's not usable.

@wKoza

wKoza commented Jan 27, 2019

Copy link
Copy Markdown
Contributor Author

If we agree with this change, I can squash and add a description of this PR in the commit message

@wKoza
wKoza force-pushed the improve_save_scroll branch from b8cdde6 to 266b848 Compare January 27, 2019 13:22
@gkalpak

gkalpak commented Jan 28, 2019

Copy link
Copy Markdown
Member

shouldn't we be using throttleTime instead of debounceTime?
We want the scroll position to be stored as one scrolls, but not too frequently. We don't want to delay scroll position updates until one stops scrolling + 500ms.

I can live with either. Theoretically, we only care about the final scroll position (after the user has stopped scrolling). The only concern would be if someone scrolled and then quickly navigated to a new doc within 400-500ms (which we could solve by other means, but throttling offers a simpler (even if not perfect) work-around for that).

@wKoza

wKoza commented Jan 28, 2019 •

Copy link
Copy Markdown
Contributor Author

(which we could solve by other means, but throttling offers a simpler (even if not perfect) work-around for that

"even if not perfect" ; Yes. IMO, the user should stay in his previous position (before his scroll and then his navigation) in this case; Otherwise, he will go back in a position that he doesn't know.

Comment thread aio/src/app/shared/scroll.service.ts Resolved
@wKoza
wKoza force-pushed the improve_save_scroll branch from cb70cce to 6eb239a Compare January 28, 2019 19:26
@wKoza

wKoza commented Feb 5, 2019

Copy link
Copy Markdown
Contributor Author

Hi @petebacondarwin ,

  • Why 500ms ? My first think was 200ms. If you read this issue, you figure out that 100 ms isn't a good option. Maybe 500ms is too much; So if we want to be more accurate, we can set 250ms, but it must be >= 200ms.

  • * requestIdleCallback, yes it's an another option but less predictive, I think

@petebacondarwin

petebacondarwin commented Feb 5, 2019 •

Copy link
Copy Markdown
Contributor
  1. Even websites that make far fewer than 5 calls per second can still get throttled, since the patch just counts up to 50 then imposes a 10 second ban, without checking over how long a period those 50 calls were made (they might have taken minutes or even hours to accumulate).

WTF??

This throttling approach of Chrome is a serious problem for us, since we are staying on the same "page" the whole time. It seems that we will only be able to record 50 push states before it blocks for 10 secs! It is not even resetting if there is no push states for 10 secs before you hit the 50 push states!

So 250ms sounds like a good compromise.

But we should look for an alternative solution...

Could we hook into the forward and back and refresh actions at the browser level and update the history state just before the navigation happens? Then we just need to track the current scroll position at that point, rather than writing to it all the time. E.g. webNavigation.onBeforeNavigate?

@wKoza

wKoza commented Feb 5, 2019

Copy link
Copy Markdown
Contributor Author

Could we hook into the forward and back and refresh actions at the browser level and update the history state just before the navigation happens? Then we just need to track the current scroll position at that point, rather than writing to it all the time.

Hmm, maybe into the forward and back actions, I'm not sure on refresh action, it's certainly more random. I intend to dig it up!

In all cases, currently, there is a bug on angular.io due to this "surprise". Should we not merge a first version ?

@petebacondarwin

Copy link
Copy Markdown
Contributor

Yes, I agree that we should land this PR (perhaps with 250ms interval) and then worry about making it better next.

@petebacondarwin petebacondarwin added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 5, 2019
@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Feb 5, 2019
@wKoza
wKoza force-pushed the improve_save_scroll branch from e9327bb to 87e6570 Compare February 5, 2019 10:24
@mary-poppins

Copy link
Copy Markdown

wKoza added 4 commits February 5, 2019 13:06
There is no debouncing when we store the scroll Position.
Currently, we have a message in the console after a while:
>Throttling history state changes to prevent the browser from hanging
see: https://bugs.chromium.org/p/chromium/issues/detail?id=786211 for more informations
…and immediately reloading

This can result in an inconsistent state
@wKoza
wKoza force-pushed the improve_save_scroll branch from 87e6570 to 69401ef Compare February 5, 2019 12:07
@mary-poppins

Copy link
Copy Markdown

@wKoza

wKoza commented Feb 5, 2019

Copy link
Copy Markdown
Contributor Author

I have done a rebase of my codebase due to an error with the ChromeDrive (hope this commit help me).

@matsko matsko added the target: patch This PR is targeted for the next patch release label Feb 5, 2019
@matsko

matsko commented Feb 5, 2019

Copy link
Copy Markdown
Contributor

@wKoza please rebase

@matsko matsko closed this in 0709f84 Feb 6, 2019
matsko pushed a commit that referenced this pull request Feb 6, 2019
matsko pushed a commit that referenced this pull request Feb 6, 2019
…and immediately reloading (#28368)

This can result in an inconsistent state

PR Close #28368
matsko pushed a commit that referenced this pull request Feb 6, 2019
There is no debouncing when we store the scroll Position.
Currently, we have a message in the console after a while:
>Throttling history state changes to prevent the browser from hanging
see: https://bugs.chromium.org/p/chromium/issues/detail?id=786211 for more informations

PR Close #28368
matsko pushed a commit that referenced this pull request Feb 6, 2019
matsko pushed a commit that referenced this pull request Feb 6, 2019
…and immediately reloading (#28368)

This can result in an inconsistent state

PR Close #28368
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release type: bug/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants