Skip to content

Commit f15bedc

Browse files
committed
fix(loaders): avoid double fetch on nested loaders
1 parent 683a798 commit f15bedc

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@
141141
"build": "pnpm run build:core && pnpm run build:runtime",
142142
"build:core": "tsup",
143143
"build:runtime": "tsup --config tsup-runtime.config.ts",
144-
"dev": "pnpm run test",
144+
"dev": "pnpm run test --ui",
145145
"docs": "vitepress dev docs",
146146
"docs:build": "vitepress build docs",
147147
"lint": "prettier -c '{src,examples,playground}/**/*.{ts,vue}'",
148148
"play": "npm -C playground run dev",
149149
"play:build": "npm -C playground run build",
150150
"release": "node scripts/release.mjs",
151151
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
152-
"test": "vitest --typecheck --ui"
152+
"test": "vitest --typecheck"
153153
},
154154
"gitHooks": {
155155
"pre-commit": "lint-staged",

src/data-loaders/defineColadaLoader.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { getRouter } from 'vue-router-mock'
2323
import { enableAutoUnmount, mount } from '@vue/test-utils'
2424
import RouterViewMock from '../../tests/data-loaders/RouterViewMock.vue'
2525
import { setActivePinia, createPinia, getActivePinia } from 'pinia'
26-
import { QueryPlugin, useQuery } from '@pinia/colada'
26+
import { useQuery, PiniaColada } from '@pinia/colada'
2727
import { RouteLocationNormalizedLoaded } from 'vue-router'
2828

2929
describe(
@@ -55,7 +55,7 @@ describe(
5555
setActivePinia(pinia)
5656
return { pinia }
5757
},
58-
plugins: ({ pinia }) => [pinia, QueryPlugin],
58+
plugins: ({ pinia }) => [pinia, PiniaColada],
5959
}
6060
)
6161

@@ -95,7 +95,7 @@ describe(
9595
plugins: [
9696
[DataLoaderPlugin, { router, ...pluginOptions }],
9797
createPinia(),
98-
QueryPlugin,
98+
PiniaColada,
9999
],
100100
},
101101
})
@@ -168,7 +168,7 @@ describe(
168168
}),
169169
{
170170
global: {
171-
plugins: [getActivePinia()!, QueryPlugin],
171+
plugins: [getActivePinia()!, PiniaColada],
172172
},
173173
}
174174
)

src/data-loaders/defineColadaLoader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ export function defineColadaLoader<Data, isLazy extends boolean>(
179179
// entries.delete(loader)
180180
// }
181181
})
182+
// avoid double reload since calling `useQuery()` will trigger a refresh
183+
// and we might also do it below for nested loaders
184+
if (entry.ext.status.value === 'loading') {
185+
reload = false
186+
}
182187
}
183188

184189
const { isLoading, data, error, ext } = entry

tests/data-loaders/tester.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,11 @@ export function testDefineLoader<Context = void>(
793793
it('can nest loaders', async () => {
794794
const spyOne = vi
795795
.fn<(...args: unknown[]) => Promise<string>>()
796+
.mockResolvedValue('ko')
796797
.mockResolvedValueOnce('one')
797798
const spyTwo = vi
798799
.fn<(...args: unknown[]) => Promise<string>>()
800+
.mockResolvedValue('ko')
799801
.mockResolvedValueOnce('two')
800802
const useLoaderOne = loaderFactory({ fn: spyOne, key: 'one' })
801803
const useLoaderTwo = loaderFactory({

0 commit comments

Comments
 (0)