Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4a50173
add notes about route and component preloading
atilafassina Oct 18, 2025
50d0a0c
fix backtick typo
atilafassina Oct 18, 2025
a2ab463
fix bad URL
atilafassina Oct 18, 2025
f364e32
"start" fetching data
atilafassina Oct 18, 2025
a4c79c1
both `<A>` and `<a>` have the preload behavior, remove ambiguous sent…
atilafassina Oct 18, 2025
7937b09
more content on lazy loading and nested components
atilafassina Oct 19, 2025
0fe3593
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 20, 2025
e640128
fix typo
atilafassina Oct 20, 2025
a46fd80
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 20, 2025
f805d73
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 20, 2025
5788b7d
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 20, 2025
3d47fe4
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 21, 2025
203df8d
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 21, 2025
b1a0fb0
clarify sentence with manually preloading
atilafassina Oct 23, 2025
4b4f2e3
better English :)
atilafassina Oct 23, 2025
143ba25
typo :)
atilafassina Oct 23, 2025
738edde
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 26, 2025
4be0415
Update src/routes/solid-router/advanced-concepts/preloading.mdx
atilafassina Oct 26, 2025
f5fdd71
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 27, 2025
c186d75
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 27, 2025
0ec7ff5
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 28, 2025
48469c4
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 28, 2025
d29d5fe
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 28, 2025
e969cad
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 28, 2025
7eec91d
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 28, 2025
f291d4d
Merge branch 'main' into preload-entries
kodiakhq[bot] Oct 31, 2025
8057066
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 4, 2025
5410b66
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 4, 2025
488749c
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 8, 2025
1406b87
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 9, 2025
b4dcd8f
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/routes/guides/routing-and-navigation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ The preload function is then passed in the `<Route>` definition:
You can export preload functions and data wrappers that correspond to routes from a dedicated `[route].data.js` or `[route].data.ts` file.
This pattern provides a way to import the data function without loading anything else.

```jsx
// src/pages/users/[id].data.js
```tsx title="src/pages/users/[id].data.js"
import { query } from "@solidjs/router";

export const getUser = query(async (id) => {
Expand Down Expand Up @@ -494,8 +493,7 @@ render(
`[id].jsx` contains the component that gets rendered.
When you wrap the function within [`createAsync`](/solid-router/reference/data-apis/create-async) with the imported function, it will yield [a signal](/routes/concepts/signals) once the anticipated promise resolves.

```jsx
// [id].jsx
```tsx title="[id].tsx"
import { createAsync } from "@solidjs/router";
import { getUser } from "./[id].data";

Expand Down
2 changes: 1 addition & 1 deletion src/routes/solid-router/advanced-concepts/data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"title": "Advanced concepts",
"pages": ["lazy-loading.mdx"]
"pages": ["preloading.mdx", "lazy-loading.mdx"]
}
22 changes: 22 additions & 0 deletions src/routes/solid-router/advanced-concepts/preloading.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Preloading
---

When using the [`<A>`](/solid-router/reference/components/a) component from Solid Router, routes are preloaded by default on link hover/focus to improve perceived performance.

To enhance preloading, you can define the `preload` function on your route definition.
When on a [SolidStart](/solid-start) application, this function can also run on the server during the initial page load to fetch data before rendering. When in a Single-Page Application (SPA), it will load the route's component and its `preload` function when the user hovers or focuses on a link.

| user action | route behavior |
| ----------- | -------------------------------------- |
| hover | with a 300ms delay to avoid excessive preloading |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious where you got the 300ms from. I can only see a 20ms timeout here

| focus | immediately |

## Imperative Preloading

You can also use the [`usePreloadRoute`](/solid-router/references/use-preload-route) helper to preload routes programmatically in response to events other than link hover/focus, such as button clicks or timers.
This helper will load only the route's component by default, but it can receive a configuration object to also load the data.

## Preloading and Lazy Loading

When a route has nested lazy components, such components will not be part of the route hierarchy, so they **will not** be preloaded with the route. To preload such components, you can use the [`usePreloadRoute`](/solid-router/references/use-preload-route) helper in the parent component to load them when needed.
24 changes: 22 additions & 2 deletions src/routes/solid-router/reference/primitives/use-preload-route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@
title: usePreloadRoute
---

`usePreloadRoute` returns a function that can be used to preload a route manually. This is what happens automatically with link hovering and similar focus based behavior, but it is available here as an API.
`usePreloadRoute` returns a function that can be used to preload a route manually.

```js
```ts
const preload = usePreloadRoute();

preload(`/users/settings`, { preloadData: true });
```

## Usage

Routes are preloaded by default when using the [`<A>`](/solid-router/reference/components/a)` component.
This helper is useful when you want to preload a route in response to some other event, such as a button click or a timer.

## Type Signature

### Parameters

| Parameter | Type | Required | Description |
| --------- | -------- | -------- | ------------------------------------ |
| `to` | `To` | Yes | The route path to preload |
| `options` | `object` | No | Configuration options for preloading |

### Options

| Option | Type | Default | Description |
| ------------- | --------- | ------- | ------------------------------------------------------------------- |
| `preloadData` | `boolean` | `false` | Whether to preload the route's data in addition to the route itself |