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

Undefined query parameter with fallback value is saved undefined in the cache #4780

Open
ancaspatariu opened this issue Dec 19, 2024 · 1 comment

Comments

@ancaspatariu
Copy link

ancaspatariu commented Dec 19, 2024

This one is rtk query related.

For a function like this:

query: ({
		page = DEFAULT_PAGE,
		size = DEFAULT_PAGE_SIZE,


	}) => {
		return {
			url: `...`,
			method: "GET",
			params: {
				page,
				size,
			},
		};
	},

If a parameter is omitted, the GET call is done properly, but the cache entry (as it is returned by api.util.selectInvalidatedBy(getState(), ["Tag"]) is saved with an undefined value instead of the fallback value.

@markerikson
Copy link
Collaborator

@ancaspatariu that looks like expected behavior to me.

You passed in undefined as the actual argument, so that's all that RTKQ has access to. RTKQ can't know that you had a default value inside the function, nor that it was intended to be used as the cache key.

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

No branches or pull requests

2 participants