WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 875243f

Browse files
committed
feat(loaders): the initial value of error is now null
BREAKING CHANGE: the initial value of undefined was a mistake (differently from data which does start as undefined). The initial state of a loader should be pending, data: undefined, and error: null
1 parent 8134519 commit 875243f

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/data-loaders/defineColadaLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export function defineColadaLoader<Data>(
168168
// force the type to match
169169
data: shallowRef<Data | undefined>(),
170170
isLoading: shallowRef(false),
171-
error: shallowRef<any>(),
171+
error: shallowRef<unknown>(null),
172172
to,
173173

174174
options,

src/data-loaders/defineLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function defineBasicLoader<Data>(
141141
// force the type to match
142142
data: shallowRef<Data | undefined>(),
143143
isLoading: shallowRef(false),
144-
error: shallowRef<ErrorDefault | null>(),
144+
error: shallowRef<ErrorDefault | null>(null),
145145
to,
146146

147147
options,

tests/data-loaders/tester.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,10 +1408,10 @@ export function testDefineLoader<Context = void>(
14081408
await p
14091409
const { data: one, error: e1 } = app.runWithContext(() => l1.loader())
14101410
const { data: two, error: e2 } = app.runWithContext(() => l2.loader())
1411-
expect(one.value).toBeUndefined()
1412-
expect(e1.value).toBeUndefined()
1413-
expect(two.value).toBeUndefined()
1414-
expect(e2.value).toBeUndefined()
1411+
expect(one.value).toBe(undefined)
1412+
expect(e1.value).toBe(null)
1413+
expect(two.value).toBe(undefined)
1414+
expect(e2.value).toBe(null)
14151415
}
14161416
)
14171417

0 commit comments

Comments
 (0)