From c2f3a2aac05f75da791ff0788c681392ef68979f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 18 Mar 2018 21:41:47 -0400 Subject: [PATCH 01/14] prefetch on mouse stop (#140) --- src/runtime/index.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/runtime/index.ts b/src/runtime/index.ts index 347fbeef9..5e643be4a 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -214,7 +214,7 @@ let prefetching: { export function prefetch(href: string) { const selected = select_route(new URL(href, document.baseURI)); - if (selected) { + if (selected && (!prefetching || href !== prefetching.href)) { prefetching = { href, promise: selected.route.load().then(mod => prepare_route(mod.default, selected.data)) @@ -222,7 +222,16 @@ export function prefetch(href: string) { } } -function handle_touchstart_mouseover(event: MouseEvent | TouchEvent) { +let mousemove_timeout: NodeJS.Timer; + +function handle_mousemove(event: MouseEvent) { + clearTimeout(mousemove_timeout); + mousemove_timeout = setTimeout(() => { + trigger_prefetch(event); + }, 20); +} + +function trigger_prefetch(event: MouseEvent | TouchEvent) { const a: HTMLAnchorElement = findAnchor(event.target); if (!a || a.rel !== 'prefetch') return; @@ -248,8 +257,8 @@ export function init(_target: Node, _routes: Route[], opts?: { store?: (data: an window.addEventListener('popstate', handle_popstate); // prefetch - window.addEventListener('touchstart', handle_touchstart_mouseover); - window.addEventListener('mouseover', handle_touchstart_mouseover); + window.addEventListener('touchstart', trigger_prefetch); + window.addEventListener('mousemove', handle_mousemove); inited = true; } From a6b1527fd38759bb8bec022dc502c32f6582b1dd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 18 Mar 2018 21:53:13 -0400 Subject: [PATCH 02/14] try using mousemove in tests --- test/common/test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/common/test.js b/test/common/test.js index ca4a063d3..8fcf7d9a2 100644 --- a/test/common/test.js +++ b/test/common/test.js @@ -308,7 +308,10 @@ function run({ mode, basepath = '' }) { .then(() => { return capture(() => { return nightmare - .mouseover('[href="blog/what-is-sapper"]') + .evaluate(() => { + const a = document.querySelector('[href="blog/what-is-sapper"]'); + a.dispatchEvent(new MouseEvent('mousemove')); + }) .wait(200); }); }) From 7303e811be7c25a7ece65ee7f637aaa1358c844f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 3 May 2018 21:54:23 -0400 Subject: [PATCH 03/14] update tests, move test app to v2 --- package.json | 16 ++++++++-------- test/app/routes/4xx.html | 8 ++++---- test/app/routes/5xx.html | 6 +++--- test/app/routes/about.html | 4 ++-- test/app/routes/blog/[slug].html | 10 +++++----- test/app/routes/blog/index.html | 10 +++++----- test/app/routes/credentials/index.html | 2 +- test/app/routes/index.html | 6 +++--- test/app/routes/preload-values/custom-class.html | 2 +- test/app/routes/preload-values/set.html | 2 +- test/app/routes/show-url.html | 2 +- test/app/routes/store.html | 2 +- 12 files changed, 35 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 2d52c5183..010824488 100644 --- a/package.json +++ b/package.json @@ -34,13 +34,13 @@ "rimraf": "^2.6.2", "sade": "^1.4.0", "sander": "^0.6.0", - "source-map-support": "^0.5.4", + "source-map-support": "^0.5.5", "tslib": "^1.9.0", "url-parse": "^1.2.0", "webpack-format-messages": "^1.0.2" }, "devDependencies": { - "@std/esm": "^0.25.3", + "@std/esm": "^0.26.0", "@types/glob": "^5.0.34", "@types/mkdirp": "^0.5.2", "@types/rimraf": "^2.0.2", @@ -53,16 +53,16 @@ "nightmare": "^3.0.0", "npm-run-all": "^4.1.2", "polka": "^0.3.4", - "rollup": "^0.57.0", - "rollup-plugin-commonjs": "^9.1.0", + "rollup": "^0.58.2", + "rollup-plugin-commonjs": "^9.1.3", "rollup-plugin-json": "^2.3.0", "rollup-plugin-string": "^2.0.2", "rollup-plugin-typescript": "^0.8.1", "serve-static": "^1.13.2", - "svelte": "^1.57.4", - "svelte-loader": "^2.5.1", - "ts-node": "^5.0.1", - "typescript": "^2.6.2", + "svelte": "^2.4.4", + "svelte-loader": "^2.9.0", + "ts-node": "^6.0.2", + "typescript": "^2.8.3", "walk-sync": "^0.3.2", "webpack": "^4.1.0" }, diff --git a/test/app/routes/4xx.html b/test/app/routes/4xx.html index df21c6bd8..c63ca8406 100644 --- a/test/app/routes/4xx.html +++ b/test/app/routes/4xx.html @@ -1,6 +1,6 @@ -<:Head> - {{status}} - + + {status} +

Not found

-

{{error.message}}

\ No newline at end of file +

{error.message}

\ No newline at end of file diff --git a/test/app/routes/5xx.html b/test/app/routes/5xx.html index 9208b047e..1425e2a8b 100644 --- a/test/app/routes/5xx.html +++ b/test/app/routes/5xx.html @@ -1,6 +1,6 @@ -<:Head> + Internal server error - +

Internal server error

-

{{error.message}}

\ No newline at end of file +

{error.message}

\ No newline at end of file diff --git a/test/app/routes/about.html b/test/app/routes/about.html index e09a72ed6..605e0db2f 100644 --- a/test/app/routes/about.html +++ b/test/app/routes/about.html @@ -1,6 +1,6 @@ -<:Head> + About - +

About this site

diff --git a/test/app/routes/blog/[slug].html b/test/app/routes/blog/[slug].html index ac5245bff..7fdc8b4b1 100644 --- a/test/app/routes/blog/[slug].html +++ b/test/app/routes/blog/[slug].html @@ -1,11 +1,11 @@ -<:Head> - {{post.title}} - + + {post.title} + -

{{post.title}}

+

{post.title}

- {{{post.html}}} + {@html post.html}