Skip to content

"placeholderData: keepPreviousData" results in double fetch #7084

@skelawsky

Description

@skelawsky

@HugeLetters
I experienced the same error as described in the topic and tried to apply your solution however another problem arose: the query is fetched twice on initial render even though the query key does not change and it only happens when I add placeholderData: prevData. Have you had the same problem??

	let prevData;
	$: documentLinesQuery = createQuery({
		queryKey: ['document-lines', perPage, page, $sorting, filters],
		queryFn: async () => {
			console.log('fetch')
			let url = new URL(`document-lines`, PUBLIC_API_URL);
			appendSearchParams({ url, perPage, page, sorting: $sorting, filters });
			return await fetch(url).then((res) => res.json());
		},
		placeholderData: prevData
	});
	$: if ($documentLinesQuery?.isSuccess) {
		prevData = $documentLinesQuery.data;
	}

image

Originally posted by @skelawsky in #5913 (comment)

I'm creating a new post because linked one seems to be closed and not visible to the others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions