Replies: 13 comments 11 replies
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
1 and 3 seem pretty reasonable. For 2, this is really tricky. This is kind of adapted from TanStack query and sticking with
My preference personally is makeQuery or createQuery. Deviating from query here are some different options:
|
Beta Was this translation helpful? Give feedback.
-
Regarding renaming cache, considering we drew inspiration from TanStack Query, I'm leaning toward |
Beta Was this translation helpful? Give feedback.
-
Is it intuitive? No. But at least it doesn't set unrealistic expectations. |
Beta Was this translation helpful? Give feedback.
-
1. Rename
|
Beta Was this translation helpful? Give feedback.
-
My ViewpointsStrongly Support Renaming the Load Function to PreloadFrom my personal experience, the load function indeed caused some confusion. When I first started using load(), I mistakenly thought that once I used load() in a route, the component for that route would automatically include the data loaded by load(). However, you actually need to create a signal in the component, such as createAsync. While it's a reasonable and clear basic principle to use signals to manage data flow, I made similar mistakes. Therefore, renaming it to preload can more accurately convey its purpose and avoid misunderstandings. No Strong Opinion on Renaming the Cache FunctionMy understanding is that functions created with the cache function are loaded as needed, especially to avoid redundant calculations on multiple loads. Because of this feature, once a function is loaded with cache in load(), it doesn't need to be recalculated when retrieved through signals in the component. Therefore, the name cache seems reasonable to me. However, if there's a better name that can more clearly convey its functionality, I would support that too. Fully Support Returning Response TypesI look forward to the great convenience this will bring. Returning response types will make type definitions more accurate and help understand the functionality, reducing potential confusion. Thanks to the developers for their hard work. I hope to keep learning and eventually contribute to the community myself. |
Beta Was this translation helpful? Give feedback.
-
The wiki entry about buffer reads: `a data buffer (or just buffer) is a region of memory used to store data temporarily while it is being moved from one place to another. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks everyone for the comments.
I will start working on 1 & 3 and hopefully in the next little bit will have more clarity on #2. Love all your feedback so far. |
Beta Was this translation helpful? Give feedback.
-
why one function? why is redirect not available when you don't want revalidate?... from reply on X: It is clearer to separate router aware from revalidatable queries. it is useful to redirect also on queries where you never want revalidate or dedupe. THEN pick a name got each of these traits:
therefore compose any or all of these as you want.
|
Beta Was this translation helpful? Give feedback.
-
I think that that familiar names like Borrowing monikers from Ports and Adapters a name like I suspect that it would be a valuable reminder that an architecturally significant boundary is being crossed. |
Beta Was this translation helpful? Give feedback.
-
Summary
This proposal looks at naming and type changes to the router that can aid in users learning journey and set the right expectations up front about the behavior of the routers Data APIs.
I'm very interested in people's feedback especially around the potential renaming of the
cache
function. Please leave comments below.Background
While I've been content with the direction of the router we've definitely seen a lot of confusion around the APIs. Gathering the feedback has lead to a few realizations where I believe we can make small adjustments that might make the purpose and capabilities of certain router features more obvious.
Proposal
This proposal involves a few small changes but the overall result I hope achieves the goal.
1. Rename
load
function topreload
We only renamed it from
data
recently, but I choseload
at the time because this function runs during preload, during route navigation, during single flight.. basically any time we potentially wanted to load things. I felt thatpreload
didn't capture the work it was doing.However,
load
has meaning from other routers that seems to put a lot more expectation there. Solid Router'sload
functions are completely optional. All the real work happens in the components. It is just a tool to lift things up for optimization reasons. Some of those optimization reasons don't even matter if the code is preloaded on hover (or if you are server rendering).We've seen people trying to build blocking/guarding patterns here to limited success and it is because these methods are designed (and have always been even when they were
data
) to be non-blocking pre-emptive aids. If these blocked they'd sort of defeat the purpose. That is to get things launching ahead of time. We know that the async data isn't available at the time they launch which is why we designed APIs that let you save the work later initially passing signals down or now with ourcache
functions.In so
load
doesn't seem to carry the right connotations. This is a pre-emptive optimization, its apreload
rather than where the actual work happens. It can fire it off, it can help with places you hover but might never navigate to, but it is not an opportunity to add yet another waterfall into the pipeline.2. Rename
cache
functionI admit I don't have a good name here yet but it is clear that developers don't understand this API. They avoid it even because it says
cache
. While we have some vision that morecache
-like functionality could be extended into this primitive in the future it isn't really that currently (like maybe add acache
option). It andaction
form a duo that handles our Responses and it isn't obvious to people that you needcache
to handle router concerns.The responsibility of
cache
is:These are a cache of sorts but they are non-persistent on reload. It is basically like Tanstack Query.
In so we probably should rename this primitive in a way that is more obvious to its purpose. Suggestions I've seen are
data
, ie (Server?) Data and Action functions similar to early SolidStart.query
similar to Tanstack.Neither of these suggest that there is Router tie in mind you. I'm definitely open to suggestions. Please leave yours in the comments.
3. Have Response Helper's return Response Types
So trying to solve types in
cache
andaction
lead to some pretty funny types. Mostly these functions can return Responses via things likejson
orredirect
where we don't want the response types to impact the output. The way we did this was have the helpers returnnever
which excludes them from the types. But it causes other confusion related to code the runs after them in functions, people not realizing they returned values etc..So what I'm proposing now is that we have a special typed generic Response type that is returned from these helpers and it is the
cache
andaction
functions that filter out theResponse
instead. This is more accurate description of what is going on here should let TS aid in understanding the functionality rather than just be a fancy trick.Impact
Hopefully these changes will make the intent of portions of the router much more obvious to people learning the APIs while still retaining their powerful behavior.
Adoption
The first 2 changes can be supported in a minor release with a phase out plan that the old names still work but are deprecated until a later minor release. The 3rd change would also happen in a minor release and hopefully won't impact the types of projects negatively since they are part of a closed cycle. Whether the filtering happens in the helper or in the
cache
oraction
function shouldn't matter since in neither cases they escape.The renaming will require some docs changes, but they can roll out as available since that part will remain backwards compatible.
Beta Was this translation helpful? Give feedback.
All reactions