-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Opt out of load
invalidation
#6294
Comments
Another idea brought up by @Conduitry is to have a separate object which contains the same parameters but in an untracked way. The disadvantage is that the API is somewhat clunky, the advantage is that you are not constrained to "access inside |
For my case, I must use the |
I found a way how I can avoid load invalidation with let symbolKeyCache;
/** @type {import('./$types').LayoutServerLoad} */
export async function load({ request }) {
if (!symbolKeyCache) {
symbolKeyCache = Reflect.ownKeys(request).find(key => key.toString() === 'Symbol(state)');
}
const query = request[symbolKeyCache].url.searchParams;
... |
Had a showerthought about a possible solution for this. I think the concept of "automatic invalidation" is inherently confusing - you did not do anything to cause that, it just happens inside the framework. Most of the time you'd rather conserve on requests rather than invalidate everything, therefore you'll want imperative control over what exactly you want to invalidate, and what you want to just simply reference. My idea is I currently opt out via const absolutelyNotSearchParams =
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(event.url), 'searchParams').get.call(event.url) and it feels very cursed to do this. One thing I like about Svelte is I don't have to wrangle with it, it's permissive. Here I feel it turned out to be the reverse. If the invalidation is preferred by default and you'd rather not change the entire API after 1.0, you can put the concept on its head and do |
@Algoinde it's not a bad idea, but firstly team should get back to this issue. |
Making this opt-in feels a little like React's We already have explicit opt-in through |
Yeah, I think simply shadowing it behind an event prop would be a good way to gain the control in a non-confusing way (which I feel the proposed untrack function is). |
So your proposal is something like |
Yeah, pretty much. Scatter it around the |
#9390 would also be solves through this, though it got me thinking that we probably also need to enhance |
@dummdidumm if you need a rerun function that uses untracked URLs you can do it by tracked part. The problem is only with functions which not include any |
The use case would be "don't rerun this unless I explictly tell it to", which you can do with |
In my case for these opt-outs I just |
Totally valid, yes, this is more a QOL thing |
Related? - Function isInvalidating(url) for load - #6495 |
At the moment I am facing the same problem. A simple goto('....', { invalidateNothing:true}) or something similar would help me a lot. |
In case someone else needs this now, you can use const someUntrackedParam = Object.getOwnPropertyDescriptor(event.params, 'some-param')?.value; |
@pabueco as I understand it's will be slower than my way, no? |
Would that look something like passing in valid import { goto } from '$app/navigation';
goto('/', {
invalidate: [
'/foo',
new URL('/example'),
(url) => url.pathname === '/bar'
]
}); |
i'm not sure if this is on-topic, but this is how i got around load invalidation when my load function depends on search params: export const load: LayoutServerLoad = async ({ request }) => {
const { searchParams } = new URL(request.url)
console.log(searchParams)
} |
@seanvelasco at least before |
Describe the problem
When running a
load
function, SvelteKit notes what dependencies the function has...url.pathname
,url.search
, etcparams.x
,params.y
fetch
await parent()
...and re-runs the function when those things change. It's possible to force an invalidation with
invalidate(resource)
(where theload
function calleddepends(resource)
) or withinvalidate()
(which invalidates allload
functions), but it's not possible to opt out of invalidation, which is occasionally helpful:Describe the proposed solution
We could add an
untrack
function toload
:Code executed synchronously inside the callback would not affect the function's dependencies.
Alternatives considered
The alternative is to require developers to be completely explicit about when
load
should re-run, or to always re-run everyload
function (which no-one wants).Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: