Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Data Source Feature Request #152

Open
taschetto opened this issue Aug 31, 2022 · 4 comments
Open

File Data Source Feature Request #152

taschetto opened this issue Aug 31, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@taschetto
Copy link

taschetto commented Aug 31, 2022

Is your feature request related to a problem? Please describe.
In a team with many developers, it can be a hassle to share client-side ids and multiple environments on LaunchDarkly. We want developers to load and manage flags from a file - as we do on server-side SDKs.

Describe the solution you'd like
In a local development environment, we want to turn the client offline so we can use a bootstrapped flag set. Ideally, this would behave just like reading flags from a file on server-side SDKs.

Describe alternatives you've considered

  • create a msw plugin so we can mock LD requests at the request level during development (which is the ideal solution since the application code would be the same as the production build)
  • provide a custom client implementation mocking the functions
@louis-launchdarkly louis-launchdarkly added the enhancement New feature or request label Sep 10, 2022
@louis-launchdarkly
Copy link
Contributor

louis-launchdarkly commented Sep 10, 2022

Hello @taschetto, Thank you for the feature request. I will discuss with the React engineer about this feature and let you know our thoughts about this.

Filed Internally as 222973.

@boxgames1
Copy link

@louis-launchdarkly any news on this?

@avinayak
Copy link

avinayak commented Mar 31, 2023

Hacky way to do this if someone needs it..

import LDContext from "launchdarkly-react-client-sdk/lib/context";
import flags from "ld_offline_flags.json";

const withLDProvider = (Component: React.ComponentType) => (
      props: React.ComponentProps<typeof Component>,
    ) => (
      <LDContext.Provider
        value={{
          flags,
          flagKeyMap: {},
          ldClient: {
            allFlags: () => flags,
            identify: () => new Promise(() => {}),
            on: () => new Promise(() => {}),
            waitUntilGoalsReady: () => new Promise(() => {}),
            track: () => new Promise(() => {}),
            variation: () => new Promise(() => {}),
            waitUntilReady: () => new Promise(() => {}),
            waitForInitialization: () => new Promise(() => {}),
            flush: () => new Promise(() => {}),
            getUser: () => ({}),
            variationDetail: () => ({
              value: false,
              variation: 0,
              reason: {
                kind: `ERROR`,
                errorKind: `FLAG_NOT_FOUND`,
              },
            }),
            setStreaming: () => new Promise(() => {}),
            off: () => new Promise(() => {}),
            alias: () => new Promise(() => {}),
            close: () => new Promise(() => {}),
          },
        }}
      >
        <Component {...props} />
      </LDContext.Provider>
    );

@taschetto
Copy link
Author

I went with https://github.com/tdeekens/flopflip.

yusinto added a commit that referenced this issue Jul 14, 2023
…#202)

**Requirements**

- [ ] I have added test coverage for new or changed functionality
- [ ] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [ ] I have validated my changes against all supported platform
versions

**Related issues**

#152

**Describe the solution you've provided**

This solution just maintains any flags that were bootstrapped, in the
event of an error while initializing the client (as is the case when I
don't use any `clientSideId` locally)

**Describe alternatives you've considered**

The alternative would be a proper offline-mode implementation that was
requested already in
#152

**Additional context**

currently using this as a patch (to be used with
[patch-package](https://www.npmjs.com/package/patch-package), add
`patches/launchdarkly-react-client-sdk+3.0.6.patch`):

```
diff --git a/node_modules/launchdarkly-react-client-sdk/lib/provider.js b/node_modules/launchdarkly-react-client-sdk/lib/provider.js
index c4f17b2..e901bb6 100644
--- a/node_modules/launchdarkly-react-client-sdk/lib/provider.js
+++ b/node_modules/launchdarkly-react-client-sdk/lib/provider.js
@@ -73,16 +73,18 @@ class LDProvider extends react_1.Component {
             const { clientSideID, flags, options } = this.props;
             let ldClient = yield this.props.ldClient;
             const reactOptions = this.getReactOptions();
-            let unproxiedFlags;
+            let unproxiedFlags = this.state.unproxiedFlags;
             let error;
             if (ldClient) {
                 unproxiedFlags = (0, utils_1.fetchFlags)(ldClient, flags);
             }
             else {
                 const initialisedOutput = yield (0, initLDClient_1.default)(clientSideID, (0, utils_1.getContextOrUser)(this.props), options, flags);
-                unproxiedFlags = initialisedOutput.flags;
-                ldClient = initialisedOutput.ldClient;
                 error = initialisedOutput.error;
+                if(!error) {
+                    unproxiedFlags = initialisedOutput.flags;
+                }
+                ldClient = initialisedOutput.ldClient;
             }
             this.setState(Object.assign(Object.assign({ unproxiedFlags }, (0, getFlagsProxy_1.default)(ldClient, unproxiedFlags, reactOptions, flags)), { ldClient, error }));
             this.subscribeToChanges(ldClient);

```
@louis-launchdarkly louis-launchdarkly changed the title Allow offline mode File Data Source Feature Request Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants