Skip to content

Commit 4cd7564

Browse files
authored
refactor: Prefech & preload on touchstart events too (#1231)
1 parent b608359 commit 4cd7564

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/components/blog-overview/index.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default function BlogOverview() {
1616
{config.blog.map(post => {
1717
const name = getRouteName(post, lang);
1818
const excerpt = post.excerpt[lang] || post.excerpt.en;
19-
const onMouseOver = () => {
19+
20+
const prefetchAndPreload = () => {
2021
BlogPage.preload();
2122
prefetchContent(post.path);
2223
};
@@ -27,10 +28,10 @@ export default function BlogOverview() {
2728
<Time value={post.date} />
2829
</div>
2930
<h2 class={s.title}>
30-
<a href={post.path} onMouseOver={onMouseOver}>{name}</a>
31+
<a href={post.path} onMouseOver={prefetchAndPreload} onTouchStart={prefetchAndPreload}>{name}</a>
3132
</h2>
3233
<p class={s.excerpt}>{excerpt}</p>
33-
<a href={post.path} onMouseOver={onMouseOver} class="btn-small">
34+
<a href={post.path} onMouseOver={prefetchAndPreload} onTouchStart={prefetchAndPreload} class="btn-small">
3435
{continueReading} &rarr;
3536
</a>
3637
</article>

src/components/content-region/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const COMPONENTS = {
1414
if (props.href && props.href.startsWith('/')) {
1515
const url = new URL(props.href, location.origin);
1616

17-
props.onMouseOver = () => {
17+
const prefetchAndPreload = () => {
1818
if (props.href.startsWith('/repl?code')) {
1919
ReplPage.preload();
2020
preloadRepl();
@@ -25,6 +25,9 @@ const COMPONENTS = {
2525

2626
prefetchContent(url.pathname);
2727
};
28+
29+
props.onMouseOver = prefetchAndPreload;
30+
props.onTouchStart = prefetchAndPreload;
2831
}
2932

3033
return <a {...props} />;

src/components/header/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ const NavLink = ({ to, isOpen, route, ...props }) => {
222222
? { onContextMenu: BrandingRedirect, 'aria-label': 'Home' }
223223
: {};
224224

225-
const onMouseOver = () => {
225+
const prefetchAndPreload = () => {
226226
if (prefetchHref.startsWith('/repl')) {
227227
ReplPage.preload();
228228
preloadRepl();
@@ -237,7 +237,8 @@ const NavLink = ({ to, isOpen, route, ...props }) => {
237237
return (
238238
<a
239239
href={href}
240-
onMouseOver={onMouseOver}
240+
onMouseOver={prefetchAndPreload}
241+
onTouchStart={prefetchAndPreload}
241242
{...props}
242243
data-route={route}
243244
{...homeProps}

src/components/sidebar/sidebar-nav.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function SidebarNavLink(props) {
7070
href={href}
7171
onClick={onClick}
7272
onMouseOver={() => prefetchContent(href)}
73+
onTouchStart={() => prefetchContent(href)}
7374
class={cx(style.link, activeCss, style['level-' + level])}
7475
>
7576
{children}

0 commit comments

Comments
 (0)