- Notifications
You must be signed in to change notification settings - Fork 330
content: Expand notes on preloading data #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
✅ Deploy Preview for solid-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
8602320
to 4a50173
Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR expands the documentation on data preloading in Solid Router, explaining how preloading works both within and outside SolidStart applications. It provides clarity on when and why to use manual preloading versus automatic preloading behavior.
- Added comprehensive documentation on automatic vs manual preloading behaviors
- Enhanced API documentation for
usePreloadRoute
with detailed type signatures - Clarified preloading mechanics with user actions and timing heuristics
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
use-preload-route.mdx | Enhanced with usage examples, type signatures, and parameter documentation |
preloading.mdx | New comprehensive guide on preloading concepts and advanced usage patterns |
data.json | Added preloading guide to advanced concepts navigation |
routing-and-navigation.mdx | Minor formatting improvements to code blocks with titles |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/routes/solid-router/reference/primitives/use-preload-route.mdx Outdated Show resolved Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
When on a [SolidStart](/solid-start) application, this function can also run on the server during the initial page load to start fetching 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 | | ||
| focus | immediately | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the SolidStart section might be more appropriate in the reference section as a callout so it doesn't get buried here.
Following that change, I also believe it might be better to show a basic code snippet of what the hover would look like. Doesn't have to be too complex, just enough to get the idea across for how it should look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code snippet is in the respective API references. This entry is to explain conceptually how preloading works in Solid Router. I added links to the the APIs so things didn't get too repetitive
Not sure what you mean about the hover snippet, that's just the browser API, there's no code from the user to manage or handle that. If they hover or focus the anchor tag, preloading will happen.
Remember: preloading is default behavior. Altering it is an advanced concept for users, most cases we want people to feel it "just works".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as it stands for me it feels more like an extension of the ref page vs an exposure to the concept as a whole. What I meant by the hover example was that it might make it feel less like a ref page if there is some form of an example on the page of what it'd look like to modify it.
My explanation wasn't entirely great (I'm sorry about that) but I'll try to give you a bit more of an idea as to what I mean tomorrow (unless @devagrawal09 has any ideas before then).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice updates here! After all the really generous time you all spent helping me on Discord, I figured the least I could do was return the favor. Curious of your thoughts.
| ||
```ts | ||
Used to lazy load components to allow for code splitting. | ||
Components are not loaded until rendered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Components are not loaded until rendered. | |
Components are not loaded until rendered or manually preloaded. |
## Preloading data in Nested Lazy Components | ||
| ||
Top-level lazy components will automatically be preloaded as well as their preload functions. | ||
Though nested lazy components will not be preloaded automatically because they are not part of the route hierarchy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though nested lazy components will not be preloaded automatically because they are not part of the route hierarchy. | |
However, nested lazy components will not be preloaded automatically because they are not part of the route hierarchy. |
| ||
Top-level lazy components will automatically be preloaded as well as their preload functions. | ||
Though nested lazy components will not be preloaded automatically because they are not part of the route hierarchy. | ||
To preload such components, you can use the `preload` method exposed on the lazy component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To preload such components, you can use the `preload` method exposed on the lazy component | |
To preload such components, you can use the `preload` method exposed on the lazy component. |
| ||
return ( | ||
<div> | ||
<button onClick={handlePreload}>Preload Nested Component</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the time the button is visible and before it's able to be clicked, <Nested />
is loaded and rendered already no?
| ||
## 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/reference/primitives/use-preload-route) helper in the parent component to load them when needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the context of this paragraph, the second sentence here seems misplaced and was the problem we were initially discussing on Discord. usePreloadRoute
is for preloading routes directly. (await lazy(string)).preload()
is what's necessary to properly preload nested lazy components. Was this maybe an editing mixup?
Let's expand on how preload works in Solid-Router within or outside a SolidStart app.
usePreloadroute
exists if that's the default behavior