Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/lit-query/src/__tests__/useIsFetching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,48 @@ describe('useIsFetching', () => {
expect(host.shadowRoot).toHaveTextContent('fetching: 0')
})

it('should not process query cache updates while disconnected', async () => {
const key = queryKey()

class Producer extends LitElement {
readonly query = createQueryController(
this,
{
queryKey: key,
queryFn: () => sleep(10).then(() => 'data'),
},
queryClient,
)
}
customElements.define(generateElementName(), Producer)

class Host extends LitElement {
updatesRequested = 0

readonly isFetching = useIsFetching(this, {}, queryClient)

override requestUpdate(
...args: Parameters<LitElement['requestUpdate']>
): void {
this.updatesRequested += 1
super.requestUpdate(...args)
}
}
customElements.define(generateElementName(), Host)
const host = new Host()
container.append(host)
await host.updateComplete

host.remove()
await host.updateComplete
const updatesAfterDisconnect = host.updatesRequested

container.append(new Producer())

await vi.advanceTimersByTimeAsync(10)
expect(host.updatesRequested).toBe(updatesAfterDisconnect)
})

it('should count all fetching queries when filters are omitted', async () => {
const key1 = queryKey()
const key2 = queryKey()
Expand Down
40 changes: 40 additions & 0 deletions packages/lit-query/src/__tests__/useIsMutating.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,46 @@ describe('useIsMutating', () => {
expect(host.shadowRoot).toHaveTextContent('mutating: 0')
})

it('should not process mutation cache updates while disconnected', async () => {
class Producer extends LitElement {
readonly mutation = createMutationController(
this,
{
mutationFn: (value: number) => sleep(10).then(() => value + 10),
},
queryClient,
)
}
customElements.define(generateElementName(), Producer)

class Host extends LitElement {
updatesRequested = 0

readonly isMutating = useIsMutating(this, {}, queryClient)

override requestUpdate(
...args: Parameters<LitElement['requestUpdate']>
): void {
this.updatesRequested += 1
super.requestUpdate(...args)
}
}
customElements.define(generateElementName(), Host)
const producer = new Producer()
const host = new Host()
container.append(producer, host)
const { mutation } = producer
await host.updateComplete

host.remove()
await host.updateComplete
const updatesAfterDisconnect = host.updatesRequested

mutation.mutate(1)
await vi.advanceTimersByTimeAsync(10)
expect(host.updatesRequested).toBe(updatesAfterDisconnect)
})

it('should count all mutating mutations when filters are omitted', async () => {
class Producer extends LitElement {
readonly mutation1 = createMutationController(this, {
Expand Down
Loading