Skip to content

Commit

Permalink
refactor: Prefech & preload on touchstart events too (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian authored Feb 7, 2025
1 parent b608359 commit 4cd7564
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/components/blog-overview/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default function BlogOverview() {
{config.blog.map(post => {
const name = getRouteName(post, lang);
const excerpt = post.excerpt[lang] || post.excerpt.en;
const onMouseOver = () => {

const prefetchAndPreload = () => {
BlogPage.preload();
prefetchContent(post.path);
};
Expand All @@ -27,10 +28,10 @@ export default function BlogOverview() {
<Time value={post.date} />
</div>
<h2 class={s.title}>
<a href={post.path} onMouseOver={onMouseOver}>{name}</a>
<a href={post.path} onMouseOver={prefetchAndPreload} onTouchStart={prefetchAndPreload}>{name}</a>
</h2>
<p class={s.excerpt}>{excerpt}</p>
<a href={post.path} onMouseOver={onMouseOver} class="btn-small">
<a href={post.path} onMouseOver={prefetchAndPreload} onTouchStart={prefetchAndPreload} class="btn-small">
{continueReading} &rarr;
</a>
</article>
Expand Down
5 changes: 4 additions & 1 deletion src/components/content-region/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const COMPONENTS = {
if (props.href && props.href.startsWith('/')) {
const url = new URL(props.href, location.origin);

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

prefetchContent(url.pathname);
};

props.onMouseOver = prefetchAndPreload;
props.onTouchStart = prefetchAndPreload;
}

return <a {...props} />;
Expand Down
5 changes: 3 additions & 2 deletions src/components/header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const NavLink = ({ to, isOpen, route, ...props }) => {
? { onContextMenu: BrandingRedirect, 'aria-label': 'Home' }
: {};

const onMouseOver = () => {
const prefetchAndPreload = () => {
if (prefetchHref.startsWith('/repl')) {
ReplPage.preload();
preloadRepl();
Expand All @@ -237,7 +237,8 @@ const NavLink = ({ to, isOpen, route, ...props }) => {
return (
<a
href={href}
onMouseOver={onMouseOver}
onMouseOver={prefetchAndPreload}
onTouchStart={prefetchAndPreload}
{...props}
data-route={route}
{...homeProps}
Expand Down
1 change: 1 addition & 0 deletions src/components/sidebar/sidebar-nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function SidebarNavLink(props) {
href={href}
onClick={onClick}
onMouseOver={() => prefetchContent(href)}
onTouchStart={() => prefetchContent(href)}
class={cx(style.link, activeCss, style['level-' + level])}
>
{children}
Expand Down

0 comments on commit 4cd7564

Please sign in to comment.