-
-
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
invalidate('...')
doesn't work after navigating to a page with parameters
#6354
Comments
invalidate('...')
doesn't work when navigating to a page with paramsinvalidate('...')
doesn't work after navigating to a page with parameters
This works as expected. The |
I'm surprised to hear that that's already not possible, I thought you could pass in any unique string to I think you should allow arbitrary values, as you said, it enables a variety of useful scenarios, such as the one in the repro I provided above, namely having |
All the urls you pass to Meaning they are passed through https://developer.mozilla.org/en-US/docs/Web/API/URL/URL before being saved. const { href } = new URL(url, location.href) Arbitrary values are possible if you make So as long as you prefix your identifier with one or more lowercase letters followed by a colon you should be fine. Example: depends(
'custom:foo',
'page:HOME_PAGE'
);
invalidate('custom:foo');
invalidate((u) => u.startsWith('page')); |
In my first proposed solution for custom dependencies in the load function (#1709) there was a lot of discussion with @Rich-Harris on how this could be implemented cleanly. I wanted to have completely arbitrary identifiers for the invalidation. However the requirements of invalidating completely custom identifiers and urls don't mix well. For urls passed to Example: function depends(identifier: string, isCustom?: boolean){}
function invalidate(identifier: string, isCustom?: boolean){} This is of cause not very nice. So I was quite happy when I came up with the solution described in my previous comment because it unifies the requirements of urls and custom identifiers. Of cause this does not give you complete freedom over what identifiers you can choose because of the (protocol like) prefix but it's close enough in my daily work. And being forced to use a prefix for custom identifiers makes it quite trivial to define namespaces/categories for them that are easily invalidated with a predicate. Long story short: There is no need for another breaking change in this case IMO. The current implementation can deal with urls and custom identifiers quite fine. The only thing that is missing is good documentation on how to use it. |
Closes #6354. Related to #6489, #6274 and #5305 Co-authored-by: Rich Harris <[email protected]> Co-authored-by: icalvin102 <[email protected]> Co-authored-by: Immanuel Calvin Herchenbach <[email protected]>
EDIT: Dont' do this, custom identifiers must start with lowercase letter followed by a
|
Wow, please make it more clear in the docs that the invalidation identifier is used to construct a URL object and we should include a colon in custom identifiers, I just spent way too much time trying to figure out why my load function wasn't rerunning. |
@cornzz
Also right I also found out that the litmus test to know if what you are passing to |
Describe the bug
Repro: https://github.com/aradalvand/sveltekit-invalidate-with-params
It seems like having a route with params (e.g.
routes/whatever/[id]
) along with a load function that havedepends(...)
doesn't work as expected, when you navigate to that page with the client-side router, and then runinvalidate('...')
, it won't work. Very weird. I'm pretty confident this is a bug.Reproduction
invalidate('user')
. You'll see that the layout's load function gets re-run, as expected:/foo/123
page, open the console and run the same command again. This time, it won't work, the layout's load function isn't re-run:Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
The problem only exists for pages that have parameters, I have no idea why, but I think this information could be useful for diagnosing the problem.
The text was updated successfully, but these errors were encountered: