Open NobleMathews opened 3 days ago
To address the issue of tutorials not properly awaiting provider readiness, follow these actionable steps:
READY
Event or Use OpenFeature.setProviderAndWait(provider)
// Assuming `client` is an instance of OpenFeature client
async function initializeFeatureFlags() {
await OpenFeature.setProviderAndWait(provider);
client.addHandler(ProviderEvents.FlagValuesChanged, () => {
// this would trigger a re-render
setUseFormalSalutation(client.getBooleanValue('use-formal-salutation', false));
});
}
// Call the initialize function
initializeFeatureFlags();
Ensure that each provider in src/datasets/providers
correctly handles the READY
event. For example, in harness.ts
:
import { OpenFeature, ProviderEvents } from '@openfeature/js-sdk';
const provider = new HarnessProvider();
OpenFeature.setProvider(provider);
provider.on(ProviderEvents.Ready, () => {
console.log('Provider is ready');
// Additional logic when the provider is ready
});
Ensure that the documentation in the docs
directory reflects the need to wait for provider readiness. For example, in a tutorial:
## Initializing Feature Flags
To ensure that the feature flags are ready before using them, you need to wait for the provider to be ready. Here's an example:
```javascript
async function initializeFeatureFlags() {
await OpenFeature.setProviderAndWait(provider);
client.addHandler(ProviderEvents.FlagValuesChanged, () => {
setUseFormalSalutation(client.getBooleanValue('use-formal-salutation', false));
});
}
initializeFeatureFlags();
By making these updates, the tutorials and provider definitions will properly handle provider readiness, ensuring that the feature flags are correctly initialized before use.
### Here are some code snippets that may help you get started:
- [src](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src)/[datasets](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets)/[providers](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets/providers)/[harness.ts](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets/providers/harness.ts):[1-15](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets/providers/harness.ts#L1-L15) | Ensure the provider definition correctly handles the READY event and updates the tutorial to wait for provider readiness.
- [src](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src)/[datasets](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets)/[providers](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets/providers)/[index.ts](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets/providers/index.ts):[1-70](https://github.com/Mayil-AI-Sandbox/openfeature.dev_march24/tree/0a20a214506cafa6f860107a286f5dae294b2717/src/datasets/providers/index.ts#L1-L70) | This snippet defines the structure and content of provider definitions, which is necessary for updating provider-related code to handle readiness events.
💡 To rerun Mayil, comment `mayil-ai rerun`. Mayil will incorporate any new context added to the ticket. Include details in your rerun comment to guide Mayil!
The [getting started tutorials]( do not properly await provider readiness. All tutorials should be updated to either wait for a
READY
event, or use a blockingprovider mutator
(ie:OpenFeature.setProviderAndWait(provider)
.Relates to: )