Skip to content

Commit 4c6fb34

Browse files
committed
fix(createSelection,createGroup): batch onboard to prevent N cache invalidations
Composables that override register() but not onboard() had two bugs: 1. Inherited onboard called base register via closure, skipping custom logic 2. No batch wrapping caused N cache invalidations + N event dispatches Add batched onboard overrides to createSelection, createGroup, createNested, useFeatures, createQueue, and useTheme. Post-batch mandate() call handles mandatory force mode where seek() needs fresh cache.
1 parent fb9b9fb commit 4c6fb34

File tree

7 files changed

+47
-3
lines changed

7 files changed

+47
-3
lines changed

packages/0/src/composables/createGroup/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ export function createGroup<
289289
}
290290

291291
function onboard (registrations: Partial<Z>[]): E[] {
292-
return registrations.map(registration => register(registration))
292+
const tickets = selection.batch(() => registrations.map(registration => register(registration)))
293+
if (toValue(mandatory) === 'force') selection.mandate()
294+
return tickets
293295
}
294296

295297
function reset () {

packages/0/src/composables/createNested/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ export function createNested<
587587
}
588588

589589
function onboard (registrations: NestedRegistration<Z>[]): E[] {
590-
return registrations.map(registration => register(registration))
590+
return group.batch(() => registrations.map(registration => register(registration)))
591591
}
592592

593593
function clear (): void {

packages/0/src/composables/createQueue/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,15 @@ export function createQueue<
416416

417417
onScopeDispose(dispose, true)
418418

419+
function onboard (registrations: Partial<Z>[]): E[] {
420+
return registry.batch(() => registrations.map(registration => register(registration)))
421+
}
422+
419423
return {
420424
...registry,
421425
register,
422426
unregister,
427+
onboard,
423428
offboard,
424429
pause,
425430
resume,

packages/0/src/composables/createSelection/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ export function createSelection<
307307
}
308308

309309
function onboard (registrations: Partial<Z>[]): E[] {
310-
return registrations.map(registration => register(registration))
310+
const tickets = registry.batch(() => registrations.map(registration => register(registration)))
311+
if (toValue(mandatory) === 'force') mandate()
312+
return tickets
311313
}
312314

313315
function reset () {

packages/0/src/composables/useFeatures/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,15 @@ export function createFeatures<
185185
}
186186
}
187187

188+
function onboard (registrations: Partial<Z>[]): E[] {
189+
return registry.batch(() => registrations.map(registration => register(registration)))
190+
}
191+
188192
return {
189193
...registry,
190194
variation,
191195
register,
196+
onboard,
192197
sync,
193198
get size () {
194199
return registry.size

packages/0/src/composables/useTheme/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,16 @@ export function createTheme<
294294
return registry.register(item as unknown as Partial<SingleTicketInput<ThemeColors>>) as unknown as E
295295
}
296296

297+
function onboard (registrations: Partial<Z>[]): E[] {
298+
return registry.batch(() => registrations.map(registration => register(registration)))
299+
}
300+
297301
return {
298302
...registry,
299303
colors,
300304
isDark,
301305
register,
306+
onboard,
302307
cycle,
303308
get size () {
304309
return registry.size

skills/vuetify0/SKILL.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ const theme = inject('theme') // Could be undefined!
140140
const [useTheme, provideTheme] = createContext<ThemeContext>('Theme')
141141
```
142142

143+
### ❌ Don't override `register` without overriding `onboard`
144+
```ts
145+
// Bad — inherited onboard calls base register via closure, skipping your logic
146+
function register (item) {
147+
const ticket = registry.register({ ...defaults, ...item })
148+
doCustomStuff(ticket)
149+
return ticket
150+
}
151+
return { ...registry, register } // onboard still calls base register!
152+
```
153+
154+
### ✅ Always pair custom `register` with batched `onboard`
155+
```ts
156+
// Good — onboard routes through your register and batches cache/events
157+
function register (item) {
158+
const ticket = registry.register({ ...defaults, ...item })
159+
doCustomStuff(ticket)
160+
return ticket
161+
}
162+
function onboard (items) {
163+
return registry.batch(() => items.map(item => register(item)))
164+
}
165+
return { ...registry, register, onboard }
166+
```
167+
143168
### ❌ Don't write SSR checks manually
144169
```ts
145170
// Bad

0 commit comments

Comments
 (0)