Skip to content
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

Fix prefetch missing cacheFor default value #2136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

talelmishali
Copy link

Fix prefetch method signature to match documentation

Description

Updates the prefetch method signature in router.ts to match the documented behavior by providing a default value for the cacheFor option. This fixes TS errors when calling router.prefetch with two arguments and aligns with the documented API.

Recreate

Calling router.prefetch to programmatically prefetch data like so:

router.prefetch(route('customers.show', row.original.id), { method: 'get' })

Results in TS2554: Expected 3 arguments, but got 2. and Uncaught TypeError: Cannot destructure property 'cacheFor' of 'undefined' as it is undefined. on runtime. This a result of not having a default value on the prefetch method on the router.

Changes

- public prefetch(href: string | URL, options: VisitOptions = {}, { cacheFor }: PrefetchOptions) {
+ public prefetch(href: string | URL, options: VisitOptions = {}, { cacheFor = 30 }: PrefetchOptions) {

Related Documentation

https://inertiajs.com/prefetching#programmatic-prefetching

Thanks for such a great work on v2 🔥!

- Update cacheFor to 30_000 (30s) 🤦🏻‍♂️
@talelmishali talelmishali changed the title Fix prefetch signature Fix prefetch missing cacheFor default value Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant