Repository navigation
Conversation
…ding isEnabled() and getValue() now require evaluation to be active before revalidating a stale entry or fetching a cache miss. Cached results and overrides are still returned immediately, and a miss still returns the existing loading or fallback value. Active stale reads still revalidate. Server flags tests cover disabled and pending stale reads, inactive cache misses, overrides while disabled, and an active stale read, and a patch changeset records the skip. Fixes databuddy-analytics#1091
|
@mvanhorn is attempting to deploy a commit to the Databuddy OSS Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| expect(manager.isEnabled("feature-on").on).toBe(true); | ||
| expect(manager.getValue("feature-on", "fallback")).toBe(true); | ||
| await sleep(20); | ||
| expect(fetchMock.calls.length).toBeGreaterThan(callsBefore); |
There was a problem hiding this comment.
getValue() refresh is untested
The active stale-read test calls isEnabled() before getValue() on the same entry. isEnabled() starts the refresh and marks the entry as refreshing, so getValue() cannot start another one. The fetch-count assertion would still pass if getValue() stopped refreshing active stale entries. Test each method with a separate manager or flag.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Split in 23907c0: getValue and isEnabled each get their own fresh manager now, and the getValue test checks the stale key shows up in the revalidation request. Removing the revalidate call from getValue makes only that test fail.
| const manager = await create({ | ||
| clientId: "test-id", | ||
| autoFetch: true, | ||
| staleTime: 1, | ||
| }); | ||
| await sleep(5); |
There was a problem hiding this comment.
Test uses forbidden loop awaits
The new inactive-read test uses await inside a for...of loop. The repository guide explicitly says “Don't use await inside loops.” Define separate tests for the disabled and pending cases, with a shared helper if needed. This repository requirement must be satisfied before merging.
Context Used: Ultracite Rules - AI-Ready Formatter and Linter (source)
There was a problem hiding this comment.
Fixed in 23907c0: the loop is gone, the disabled and pending cases are separate tests sharing a helper, same assertions.
Run the disabled and pending stale-read cases as separate tests sharing a helper instead of awaiting inside a loop, and test isEnabled() and getValue() revalidation on separate managers so each asserts its own refresh request for the stale key.
Description
isEnabled() and getValue() now require evaluation to be active before revalidating a stale entry or fetching a cache miss. Cached results and overrides are still returned immediately, and a miss still returns the existing loading or fallback value. Active stale reads still revalidate. Server flags tests cover disabled and pending stale reads, inactive cache misses, overrides while disabled, and an active stale read, and a patch changeset records the skip.
After a flag is cached, synchronous isEnabled() and getValue() reads still start a background evaluation once that entry is stale, including when the manager is disabled or the session is still pending. The caller keeps receiving the cached flag while an extra evaluation request goes out. On a stale cache hit, both methods call revalidate() when the entry is stale and shouldSkipFetch() is false. On a cache miss, they start a background getFlag() when canFetchOnRead() is true. Neither branch checks config.disabled or config.isPending.
Closes #1091
Slice
Checklist
stagingand does not include another unmerged PR unless it is named above.Not claimed:
npm testcould not run in this environment (dotenv is not installed).staging; after it closes, this branch will not be reused for another change.Not claimed:
stagingwas not run locally either.Not claimed: the same reason as the box above applies.
AI disclosure
AI was used for assistance.
Summary by cubic
isEnabled()andgetValue()skip background flag revalidation and cache-miss fetches when evaluation is disabled or the session is pending, instead of firing unnecessary network requests.config.disabledandconfig.isPendingto be false before revalidating or fetching.isEnabled()andgetValue()on separate managers.Fixes #1091.
Written for commit 23907c0. Summary will update on new commits.