canalun / brick-break-anywhere

let's break bricks anywhere!
63 stars 3 forks source link

Save and restore scrollX/Y between plays #14

Open igrep opened 2 months ago

igrep commented 2 months ago

How to reproduce

  1. Open a large web page that doesn't fit within the window size.
  2. Scroll down/right to somewhere that shows a different elements from the origin.
  3. Play the game.
  4. Replay by the "Replay" button after game over.

Expected Result

The game starts at the same viewport, which we see before reloading.

Actual Result

The game starts at the original viewport, which we see at first when visiting the page. The scroll state gets back to the original because brick-break-anywhere always reloads to refresh when replaying.

Side Note

I found this problem while creating https://github.com/canalun/brick-break-anywhere/pull/13, then guessed it'd be hard to fix then gave up. Sorry.

canalun commented 1 month ago

@igrep

Thank you for the report! You don't have to apologize anything:)

It seems to be difficult to fix it, because the initial state of the page is not necessarily the same as the state of when the game is being played. Lazy loading, SPA and etc.

Hope any good idea occurred to us sometime😄

igrep commented 1 month ago

It seems to be difficult to fix it, because the initial state of the page is not necessarily the same as the state of when the game is being played. Lazy loading, SPA and etc.

I thought in reverse. There's an option that makes things simpler:

  1. Drop most changes of https://github.com/canalun/brick-break-anywhere/pull/13 (Specifically, https://github.com/canalun/brick-break-anywhere/pull/13/commits/e5ead659cf3f13dc71e02c865776f08bf54774f4, https://github.com/canalun/brick-break-anywhere/pull/13/commits/31f0c7005447b8c8b558a61e2b4f7123e16c2cc5, and https://github.com/canalun/brick-break-anywhere/pull/13/commits/12c7f5388700581a373decda998a4bffbf957668)
  2. Make the "Replay (Reload Page)" button really just reload. I think now the label should be "Reload to Replay".

Restoring state including scrollX/Y is actually too difficult (perhaps impossible), so making it user's job could be an idea. Current behavior may be incomplete.