Skip to content

chore: adding deprecated flag hooks#1166

Open
joker23 wants to merge 3 commits intomainfrom
skz/sdk-1993/deprecated-hooks
Open

chore: adding deprecated flag hooks#1166
joker23 wants to merge 3 commits intomainfrom
skz/sdk-1993/deprecated-hooks

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Mar 10, 2026

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

sdk-1993


Note

Medium Risk
Adds new public React hooks API surface (even if deprecated) and a proxy-based useFlags implementation that could affect evaluation/event behavior; changes are covered by focused unit tests and do not touch auth/security paths.

Overview
Adds a new deprecated-hooks export surface to the React SDK: useFlag, useFlagDetail, and useFlags are now available from client/index.ts and emit a client.logger.warn deprecation notice on mount.

useFlag/useFlagDetail provide typed single-flag reads (dispatching to the appropriate *Variation/*VariationDetail method based on defaultValue) and re-render only on change:<key> events, while useFlags returns a proxy over client.allFlags() that triggers (and caches) client.variation calls on property reads and re-renders on the global change event.

Adds comprehensive jsdom tests plus test wrappers to validate method dispatch, subscription/unsubscription behavior, rerender behavior on flag/context/key changes, deprecation warnings, and the useFlags proxy caching behavior.

Written by Cursor Bugbot for commit df5b8a6. This will update automatically on new commits. Configure here.


Open with Devin

@github-actions
Copy link
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25566 bytes
Compressed size limit: 26000
Uncompressed size: 125383 bytes

@github-actions
Copy link
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 172130 bytes
Compressed size limit: 200000
Uncompressed size: 800872 bytes

@github-actions
Copy link
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 24212 bytes
Compressed size limit: 25000
Uncompressed size: 83755 bytes

@github-actions
Copy link
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 21281 bytes
Compressed size limit: 24000
Uncompressed size: 110213 bytes

@joker23 joker23 force-pushed the skz/sdk-1993/deprecated-hooks branch from 2c96e42 to df5b8a6 Compare March 10, 2026 00:43
@joker23
Copy link
Contributor Author

joker23 commented Mar 10, 2026

@cursor review

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implementation changes starts here

@joker23 joker23 force-pushed the skz/sdk-1993/deprecated-hooks branch from 8e0d270 to 9311409 Compare March 10, 2026 18:09
@joker23 joker23 marked this pull request as ready for review March 10, 2026 19:48
@joker23 joker23 requested a review from a team as a code owner March 10, 2026 19:48
@@ -0,0 +1,4 @@
export { useFlag } from './useFlag';
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure why we need useFlag or useFlagDetail. These didn't exist in the 3.x react SDK.

* @param reactContext Optional React context to read from. Defaults to the global `LDReactContext`.
* @returns All current flag values as `T`, wrapped in a proxy that records evaluations.
*
* @deprecated Use `useLDClient` with the client's variation methods directly. This hook will be
Copy link
Member

Choose a reason for hiding this comment

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

I think that the use here should be called out that this is to ease migration. That you should use the useVariation hooks.

});

await page.goto(url);
// Retry page.goto until the entity is ready (race-condition guard)
Copy link
Member

Choose a reason for hiding this comment

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

This makes me a smidge nervous.

* @deprecated Use `useLDClient` with the client's variation methods directly. This hook will be
* removed in a future major version.
*/
export function useFlags<T extends LDFlagSet = LDFlagSet>(
Copy link
Member

Choose a reason for hiding this comment

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

How does this work with Camelization?

// small subset of flags. In this case, any flag updates will cause a reset of the cache.
// It is recommended to use the typed variation hooks (useBoolVariation, useStringVariation,
// useNumberVariation, useJsonVariation) for better performance when reading a subset of flags.
const cache = new Map<string, unknown>();
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure about the cache with regards to experiment exposure.

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