Skip to content

feat(data)!: preload flag for AsyncDataService.createLazy - #171

Merged
kunalkindra merged 3 commits into
mainfrom
kkindra/create-lazy-preload
Aug 17, 2026
Merged

feat(data)!: preload flag for AsyncDataService.createLazy#171
kunalkindra merged 3 commits into
mainfrom
kkindra/create-lazy-preload

Conversation

@kunalkindra

@kunalkindra kunalkindra commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

What

createLazy now takes a single object argument and gains an optional preload flag:

AsyncDataService.createLazy({
  load,              // () => Promise<Service>  (may take args)
  properties,        // per-property descriptors
  preload?: boolean, // default false
});

When preload: true, the service is warmed at browser idle via requestIdleCallback instead of waiting for the first property access — so the first real send / read / call never races a cold load. Defaults to false; it is a no-op where requestIdleCallback is unavailable (SSR / Node / older browsers), degrading to the existing lazy-on-first-touch behavior.

Why

A lazy service loads only on first property access. That keeps heavy imports out of the initial bundle, but the first touch pays for the load — and if that touch happens right before the page tears down (e.g. an analytics event fired immediately before a navigation), the load can lose the race and the call is dropped. preload: true closes that window without giving up laziness.

Breaking change

The signature changed from positional createLazy(load, properties) to a single object createLazy({ load, properties, preload? }). Every existing call site must migrate:

// before
createLazy(load, { data: 'observe', fetch: 'fn:promise' });

// after
createLazy({ load, properties: { data: 'observe', fetch: 'fn:promise' } });

Tests / docs

  • All internal call sites migrated (create-lazy.test.ts, example.ts); the @ts-expect-error type-safety tests are preserved.
  • New tests: preload unset performs no eager load; preload: true warms the service before any property touch and dedupes with the first real access.
  • Updated create-lazy.md and the async-data-service README to the object form.
  • typecheck, lint, and the full data-package suite (2963 tests) pass.

Also included

A docs(data) commit adds a Corporate contributors section to the root README documenting how to contribute from a personal GitHub identity (SSH host aliases with IdentitiesOnly) when a corporate/EMU account can't fork or push — requested during review.

@kunalkindra
kunalkindra force-pushed the kkindra/create-lazy-preload branch from e306c4c to f143312 Compare August 17, 2026 16:14
Comment thread packages/data/src/service/async-data-service/create-lazy.ts
@kunalkindra
kunalkindra force-pushed the kkindra/create-lazy-preload branch from f143312 to 53f32e2 Compare August 17, 2026 17:39
@kunalkindra kunalkindra changed the title feat(data): optional preload scheduler for AsyncDataService.createLazy feat(data)!: preload flag for AsyncDataService.createLazy Aug 17, 2026

@krisnye krisnye left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

kunalkindra and others added 3 commits August 17, 2026 12:35
BREAKING CHANGE: createLazy now takes a single object argument
{ load, properties, preload? } instead of positional (load, properties).

Adds an optional `preload` boolean (default false). When true, the service is
warmed at browser idle via requestIdleCallback instead of waiting for the first
property access, so the first real call never races a cold load. No-op where
requestIdleCallback is unavailable (SSR / Node / older browsers).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documents contributing from a personal GitHub identity when a corporate/EMU
account can't fork or push to the public repo, using ~/.ssh/config host aliases
with IdentitiesOnly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Minor bump signaling the breaking createLazy signature change (positional →
single object argument). Pre-1.0, so breaking lands as a minor version.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kunalkindra
kunalkindra force-pushed the kkindra/create-lazy-preload branch from c21c8f3 to e04599b Compare August 17, 2026 19:35
@kunalkindra
kunalkindra merged commit 9f6e07c into main Aug 17, 2026
2 of 3 checks passed
@kunalkindra
kunalkindra deleted the kkindra/create-lazy-preload branch August 17, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants