Skip to content

Commit

Permalink
feat: run loaders with access to global inject and provide
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 19, 2023
1 parent 2d15df0 commit 9d95e27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/data-fetching_new/defineLoader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ import {
import { setCurrentContext } from './utils'
import { enableAutoUnmount, mount } from '@vue/test-utils'
import { getRouter } from 'vue-router-mock'
import { DataLoaderPlugin, setupLoaderGuard } from './navigation-guard'
import { DataLoaderPlugin } from './navigation-guard'
import { UseDataLoader } from './createDataLoader'
import { mockPromise, mockedLoader } from '~/tests/utils'
import RouterViewMock from '~/tests/data-loaders/RouterViewMock.vue'
import ComponentWithNestedLoader from '~/tests/data-loaders/ComponentWithNestedLoader.vue'
import {
dataOneSpy,
dataTwoSpy,
useDataOne,
} from '~/tests/data-loaders/loaders'
import { dataOneSpy, dataTwoSpy } from '~/tests/data-loaders/loaders'
import type { RouteLocationNormalizedLoaded } from 'vue-router'

describe('defineLoader', () => {
Expand Down
15 changes: 9 additions & 6 deletions src/data-fetching_new/navigation-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ export function setupLoaderGuard(
return
}
// keep track of loaders that should be committed after all loaders are done
const ret = loader._.load(to, router).then(() => {
// for immediate loaders, the load function handles this
if (commit === 'after-load') {
return loader
}
})
const ret = app
// allows inject and provide APIs
.runWithContext(() => loader._.load(to, router))
.then(() => {
// for immediate loaders, the load function handles this
if (commit === 'after-load') {
return loader
}
})
// on client-side, lazy loaders are not awaited, but on server they are
return IS_CLIENT && lazy
? undefined
Expand Down

0 comments on commit 9d95e27

Please sign in to comment.