Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 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
8458d45
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 13, 2025
2a63b2d
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 14, 2025
45d613e
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 15, 2025
488f277
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 15, 2025
a0d27d3
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 15, 2025
9a097df
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 15, 2025
d9bc799
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 15, 2025
243f68f
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 17, 2025
4a60374
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 17, 2025
3b51452
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 17, 2025
d30f180
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 17, 2025
05aed52
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 17, 2025
ebd7e4f
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 17, 2025
5a56fe7
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 17, 2025
6d1fd5a
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 19, 2025
3ee97d1
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 22, 2025
51bd179
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 23, 2025
5a76a74
Merge branch 'main' into preload-entries
kodiakhq[bot] Nov 27, 2025
4ea8416
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 1, 2025
6af3c13
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 1, 2025
2a9eafc
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 2, 2025
d646c27
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 2, 2025
955c3e6
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 2, 2025
0bc8489
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 9, 2025
ef334aa
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 9, 2025
98ce2d4
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 9, 2025
30cf407
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 9, 2025
5094134
update pages
LadyBluenotes Dec 11, 2025
b763734
fix example
LadyBluenotes Dec 11, 2025
3c85b53
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
3cff9dc
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
d9cceb1
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
717d07e
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
df2eb80
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
2f870f4
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
960d3f1
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
ec2e366
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
599dd02
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
f2322e2
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 13, 2025
6714733
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 16, 2025
ebf09d6
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 16, 2025
66c94ec
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 16, 2025
14a5cc6
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 16, 2025
03688e9
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 16, 2025
e44a38d
Merge branch 'main' into preload-entries
kodiakhq[bot] Dec 16, 2025
c31ce54
Update note on SSR and route preload functions
LadyBluenotes Dec 17, 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 @@ -461,8 +461,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 @@ -509,8 +508,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](/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
79 changes: 68 additions & 11 deletions src/routes/reference/component-apis/lazy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,81 @@ description: >-
performance. Components load on-demand and integrate with Suspense.
---

```ts
The `lazy` helper wraps a dynamic import and returns a component that loads on demand.
Lazy components accept the same props as their eager counterparts and integrate with `<Suspense>` boundaries.

## Import

```tsx
import { lazy } from "solid-js"
import type { Component } from "solid-js"
```

## Type

```tsx
function lazy<T extends Component<any>>(
fn: () => Promise<{ default: T }>
fn: () => Promise<{ default: T }>
): T & { preload: () => Promise<T> }
```

Used to lazy load components to allow for code splitting.
Components are not loaded until rendered.
Lazy loaded components can be used the same as its statically imported counterpart, receiving props etc.
Lazy components trigger `<Suspense>`
## Parameters

### `fn`

- **Type:** `() => Promise<{ default: T }>`
- **Required:** Yes

Dynamic import that resolves to the component module, exposing the component as the `default` export.

## Return value

`lazy` returns a renderable component compatible with `T`.
The component exposes a `preload()` method that resolves the underlying module.

| Property | Type | Description |
| -------- | ---- | ----------- |
| `preload` | `() => Promise<T>` | Loads the module without rendering and returns the resolved component. |

## Examples

### Basic usage

```tsx title="app.tsx"
import { lazy } from "solid-js"

const ComponentA = lazy(() => import("./ComponentA"))

function App(props: { title: string }) {
return <ComponentA title={props.title} />
}
```

### Preloading nested lazy components

```tsx
// wrap import
const ComponentA = lazy(() => import("./ComponentA"));
import { lazy } from "solid-js"
import type { Component } from "solid-js"

const Nested = lazy(() => import("./Nested"))

// use in JSX
<ComponentA title={props.title} />
const ComponentWithPreload = () => {
const [showNested, setShowNested] = createSignal(false)

return (
<div>
<button
onMouseEnter={() => Nested.preload()}
onClick={() => setShowNested(true)}
>Preload Nested Component</button>
<Show when={showNested()}>
<Nested />
</Show>
</div>
)
}
```

## See also

- [`Suspense`](https://docs.solidjs.com/reference/component-apis/suspense)
- [Router preloading guide](/solid-router/advanced-concepts/preloading)
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"]
}
44 changes: 44 additions & 0 deletions src/routes/solid-router/advanced-concepts/preloading.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Preloading
---

Preloading smooths navigation by resolving route code and data before a user completes a transition.
Solid Router listens for intent signals, such as hover and focus, and primes the matching route after a short delay to balance responsiveness and network cost.
Understanding the timing and scope of this work lets you decide when to rely on the default behaviour and when to layer custom strategies.

| user action | route behaviour |
| ----------- | --------------- |
| hover | waits roughly 20 ms before preloading |
| focus | preloads immediately |

## How Solid Router Detects Intent

Anchors registered with Solid Router emit hover and focus events that feed a small scheduler.
The router debounces the hover signal for 20ms to ignore incidental pointer passes while still reacting quickly to purposeful movement.
When the delay elapses, the router loads the route module and runs its preload routine so that navigation has the assets it needs when the user commits.

Route modules can export a [`preload`](/solid-router/reference/preload-functions/preload) function that receives params, search values, and router context.
The function lets you seed caches, warm derived computations, or coordinate streaming behaviours without blocking the eventual render.

> [!NOTE]
> SSR invokes route `preload` functions during the initial server render and resumes them on the client during hydration.
> Keep these functions pure so the hydrated client does not need to undo server work when it takes over.

## Imperative Preloading Hooks

Not every interaction funnels through an anchor element.
The [`usePreloadRoute`](/solid-router/reference/primitives/use-preload-route) primitive exposes the same scheduling behaviour for imperative flows like flyout previews, timers, or observer driven experiences.

This helper mirrors the router behaviour by resolving the module, optionally running the loader, and caching the result for the eventual navigation.
Empirical tuning of delay values helps you avoid excessive prefetching in dense UIs while still keeping high intent interactions snappy.

## Coordinating Nested Lazy Components

Nested lazy components live outside the router hierarchy, so route preloading does not automatically warm them.
The component API [`lazy()`](/reference/component-apis/lazy) exposes a `preload()` method that resolves a component without rendering it.
Calling both the route preload and the nested component preload can keep large detail panels responsive when a user hovers or focuses on the entry point.

Balancing manual preloading requires observing real user flows so you avoid prefetching large bundles that the user never requests.
Profiling tools help you spot whether preloading reduces long tasks or simply shifts work earlier without net gains.

To learn more about lazy loading components, see the [lazy documentation](/reference/component-apis/lazy#preloading-data-in-nested-lazy-components).
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 @@ -15,10 +15,30 @@ description: >-
prefetching route data before navigation in your SolidJS app.
---

`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 within Solid Router contexts.
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 |