Describe the bug
I got this error on our production website, tracked using Sentry:
TypeError: Cannot read property 'x' of undefined
at ? (/client/client.8caa5d97.js:16:2552)
at Generator.next(<anonymous>)
at a(/client/client.8caa5d97.js:16:86)
Here's the link: https://sentry.io/share/issue/20ae1300a33f48f58457ffce7c96925a/
**Fix**
I was able to zero down on the line here: https://github.com/sveltejs/sapper/blob/master/runtime/src/app/router/index.ts#L223. It seems like sometimes `let scroll = scroll_history[id];` might be undefined, and then calling `scrollTo(scroll.x, scroll.y)` throws an error. A proposed fix for this is to change:
if (popstate || deep_linked) {
scrollTo(scroll.x, scroll.y);
}
to:
if (scroll && (popstate || deep_linked)) {
scrollTo(scroll.x, scroll.y);
}
**Stacktraces**

**Information about your Sapper Installation:**
- The output of `npx envinfo --system --npmPackages svelte,sapper,rollup,webpack --binaries --browsers`
System:
OS: macOS 10.15.6
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 1002.30 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.5.0 - /usr/local/bin/node
npm: 6.14.6 - ~/Projects/koj/koj/node_modules/.bin/npm
Browsers:
Chrome: 85.0.4183.121
Safari: 14.0
npmPackages:
rollup: ^2.29.0 => 2.29.0
sapper: ^0.28.10 => 0.28.10

Your hosting environment: AWS EC2 running a Docker container that serves the full-stack Sapper server
If it is an exported (npm run export) or dynamic application: Dynamic
@Conduitry Is this an invalid issue?
I also wonder why this was closed @Conduitry. I experience the same intermittent issue with "Cannot read property 'x' of undefined" as described above using latest Sapper (v0.28.10)
I've opened a PR to make sure that scroll exists before trying to access its PR.
@Conduitry, do you think we can open this issue? I've seen this error 14 times on production in the past two weeks.
I can reproduce it:
Sapper stores/recovers only an id from the History API, not the scroll state. The first time we go back from the Svelte site to the application the browser takes care of the scroll, so no error happens. The next time, Sapper tries to restore the scroll position, but it can't because scroll data was gone in the moment we went outside the application (clicking the Svelte link).
Looks like @rcabralc has reproduced this well. I'm seeing this too. Let's re-open this issue and evaluate my PR #1594? I think just checking for scroll existing before accessing it is enough.
馃敂 Can we re-open this issue? @benmccann @Conduitry
We also have this issue happening from time to time.
TypeError: undefined is not an object (evaluating 'n.x')
File "webpack:///./src/node_modules/@sapper/app.mjs", line 225, in navigate
scrollTo(scroll.x, scroll.y);
File "[native code]", line unknown, in generatorResume
File "webpack:///./src/node_modules/@sapper/app.mjs", line 25, in __awaiter
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
File "[native code]", line unknown, in promiseReactionJob
I re-implemented scroll tracking in SvelteKit so that it's both simpler and will work if you leave the site and come back
I merged https://github.com/sveltejs/sapper/pull/1594 to avoid the issue in Sapper. Scroll history will be lost if you leave the site and come back, but the errors will no longer occur
When it is planned to release the fixes listed in "Unreleased" section?
Most helpful comment
I can reproduce it:
Sapper stores/recovers only an id from the History API, not the scroll state. The first time we go back from the Svelte site to the application the browser takes care of the scroll, so no error happens. The next time, Sapper tries to restore the scroll position, but it can't because scroll data was gone in the moment we went outside the application (clicking the Svelte link).