Commit 324bbce
authored
feat: allow bootstraped flags to be used even if client fails to init (#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);
```2 files changed
+39
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
172 | 206 | | |
173 | 207 | | |
174 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| |||
0 commit comments