Commit Graph

95 Commits

Author SHA1 Message Date
OpenFeature Bot ee236396cd
chore(main): release react-sdk 1.0.1 (#1235)
🤖 I have created a release *beep* *boop*
---


##
[1.0.1](https://github.com/open-feature/js-sdk/compare/react-sdk-v1.0.0...react-sdk-v1.0.1)
(2025-08-18)


### 🐛 Bug Fixes

* **react:** re-evaluate flags on re-render to detect silent provider …
([#1226](https://github.com/open-feature/js-sdk/issues/1226))
([3105595](3105595926))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2025-08-18 16:26:25 +00:00
Michael Beemer 3105595926
fix(react): re-evaluate flags on re-render to detect silent provider … (#1226)
## This PR

- Added `useEffect` that runs on re-render to re-evaluate the flag value
- Only updates state if the resolved value actually changed (using
`isEqual` comparison)
- Used lazy initialization for `useState` to avoid redundant initial
evaluation
  - Added `useCallback` memoization for event handlers
  - Fixed `AbortController` scope issue

### Notes

This resolves a subtle issue where the provider state may update without
emitting a change event, leading to confusing results. The `useFlag`
hook sets the initial evaluated value in a `useState`. Since this wasn't
in a closure, this evaluation happened any time the component using the
hook rerendered but the result was essentially ignored. Adding a logging
hook shows that the current results but since this evaluation was made
in an existing `useState`, the result had no effect.

This resolves a subtle issue where the provider state may update without
emitting a change event, leading to stale flag values being displayed.

The `useFlag` hook was evaluating the flag on every re-render (as part
of the `useState` initialization), but because `useState` only uses its
initial value on the first render, these subsequent evaluations were
being discarded. This meant that even though the hook was fetching the
correct updated value from the provider on each re-render, it was
throwing that value away and continuing to display the stale cached
value.

Adding a logging hook would show the correct evaluation happening
(proving the provider had the updated value), but the UI would remain
stuck with the old value because the `useState` was ignoring the
re-evaluated result.

The fix ensures that these re-evaluations on re-render actually update
the component's state when the resolved value changes.

The key insight is that the evaluation WAS happening on every re-render
(due to how useState works), but React was discarding the result. Your
fix makes those evaluations actually matter by checking if the value
changed and updating state accordingly.

Original thread:
https://cloud-native.slack.com/archives/C06E4DE6S07/p1754508917397519

### How to test

I created a test that reproduced the issue, and it failed. I then
implemented the changes and verified that the test passed.

---------

Signed-off-by: Developer <developer@example.com>
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Co-authored-by: Developer <developer@example.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Lukas Reining <lukas.reining@codecentric.de>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2025-08-18 15:08:51 +00:00
OpenFeature Bot 07a3d85742
chore(main): release react-sdk 1.0.0 (#1154)
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.11...react-sdk-v1.0.0)
(2025-04-14)


###  New Features

* add polyfill for react use hook
([#1157](https://github.com/open-feature/js-sdk/issues/1157))
([5afe61f](5afe61f9e3))
* add support for abort controllers to event handlers
([#1151](https://github.com/open-feature/js-sdk/issues/1151))
([6a22483](6a224830fa))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2025-04-14 17:03:15 +00:00
Michael Beemer 5afe61f9e3
feat: add polyfill for react use hook (#1157)
## This PR

- adds an internal `use` polyfill
- refactors suspense support to maintain state across rerenders

### Notes

Previously, the Next.JS build process would timeout when using a
suspense flag hook. The reason for this is because the noop provider
(which is used during a build) is never ready. That meant that the
promise thrown to initiate suspense never resolved. To address this,
I've added global state using a weak map that's keyed off a provider. A
`useRef` won't help because the value is only retained if the component
renders successfully.

> [!NOTE]
> This unblocks suspense in our demo app but does not mean NextJS is
officially support (yet).

### How to test

I've added some tests and manually tested in the Toggle Shop.

---------

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2025-04-10 12:06:19 +00:00
Michael Beemer 6a224830fa
feat: add support for abort controllers to event handlers (#1151)
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2025-02-26 16:17:28 -05:00
OpenFeature Bot 23ba0b3d8c
chore(main): release react-sdk 0.4.11 (#1122)
🤖 I have created a release *beep* *boop*
---


##
[0.4.11](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.10...react-sdk-v0.4.11)
(2025-02-07)


###  New Features

* export useOpenFeatureClientStatus hook
([#1082](https://github.com/open-feature/js-sdk/issues/1082))
([4a6b860](4a6b860544))


### 🧹 Chore

* update sdk peer
([#1142](https://github.com/open-feature/js-sdk/issues/1142))
([8bb6206](8bb620601e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2025-02-07 21:05:41 +00:00
Michael Beemer 8bb620601e
chore: update sdk peer (#1142)
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2025-02-07 16:02:31 -05:00
Will C. 4a6b860544
feat: export useOpenFeatureClientStatus hook (#1082)
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## This PR
<!-- add the description of the PR here -->

exposes the internal open feature client status hook so developers can
act on non-ready resolved states

### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->

Fixes #1036

### Notes
<!-- any additional notes for this PR -->

### Follow-up Tasks
<!-- anything that is related to this PR but not done here should be
noted under this section -->
<!-- if there is a need for a new issue, please link it here -->

### How to test
<!-- if applicable, add testing instructions under this section -->

---------

Signed-off-by: William Chou <iam@willchou.dev>
Signed-off-by: Will Chou <w.chou06@gmail.com>
Co-authored-by: Lukas Reining <lukas.reining@codecentric.de>
2025-01-28 19:40:48 +00:00
OpenFeature Bot 52c8de630b
chore(main): release react-sdk 0.4.10 (#1105)
🤖 I have created a release *beep* *boop*
---


##
[0.4.10](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.9...react-sdk-v0.4.10)
(2024-12-18)


### 🔄 Refactoring

* export public option types
([#1101](https://github.com/open-feature/js-sdk/issues/1101))
([16321c3](16321c31f2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
Co-authored-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2024-12-18 13:58:49 -05:00
Michael Beemer 16321c31f2
refactor: export public option types (#1101)
## This PR

- renames the `shared` folder to `internal` to prevent accident exports
- export public option types

### Notes

This will make it easier for devs who need access to the option types.

---------

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2024-12-10 14:12:17 -05:00
OpenFeature Bot 3c9f2c6e36
chore(main): release react-sdk 0.4.9 (#1076)
🤖 I have created a release *beep* *boop*
---


##
[0.4.9](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.8...react-sdk-v0.4.9)
(2024-12-04)


###  New Features

* re-render if flagsChanged is falsy
([#1095](https://github.com/open-feature/js-sdk/issues/1095))
([78516f4](78516f4181))


### 📚 Documentation

* fix typos, links, and format
([#1075](https://github.com/open-feature/js-sdk/issues/1075))
([418409e](418409e3fa))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-12-04 13:36:51 -05:00
Todd Baert 78516f4181
feat: re-render if flagsChanged is falsy (#1095)
Adds an improvement to the React SDK which supports re-renders if the
[flags
changed](https://open-feature.github.io/js-sdk/types/_openfeature_server_sdk.ConfigChangeEvent.html)
array from a provider event is falsy.

Since some providers have no knowledge of flags which are changed, this
allows them to support dynamic re-rendering by not defining this
property. If the prop is null/undefined, we diff all flags... If the
property is explicitly set to an empty array, that means no flags have
changed and the React SDK skips all diff checks.

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-12-04 18:31:56 +00:00
Michael Beemer 418409e3fa
docs: fix typos, links, and format (#1075)
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2024-11-05 13:06:41 -05:00
OpenFeature Bot 57ec47bb21
chore(main): release react-sdk 0.4.8 (#1071)
🤖 I have created a release *beep* *boop*
---


##
[0.4.8](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.7...react-sdk-v0.4.8)
(2024-10-29)


### 🧹 Chore

* bump minimum web peer
([#1072](https://github.com/open-feature/js-sdk/issues/1072))
([eca8205](eca8205da7))


### 📚 Documentation

* add tracking sections
([#1068](https://github.com/open-feature/js-sdk/issues/1068))
([e131faf](e131faffad))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-10-29 14:08:09 -04:00
Todd Baert eca8205da7
chore: bump minimum web peer (#1072)
- require web 1.3.0+ for tracking

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-10-29 18:03:30 +00:00
Todd Baert e131faffad
docs: add tracking sections (#1068)
- adds tracking to all relevant READMEs

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-10-29 13:12:55 -04:00
OpenFeature Bot 21212cdde0
chore(main): release react-sdk 0.4.7 (#1028)
🤖 I have created a release *beep* *boop*
---


##
[0.4.7](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.6...react-sdk-v0.4.7)
(2024-10-29)


###  New Features

* avoid re-resolving flags unaffected by a change event
([#1024](https://github.com/open-feature/js-sdk/issues/1024))
([b8f9b4e](b8f9b4ebaf))
* implement tracking as per spec
([#1020](https://github.com/open-feature/js-sdk/issues/1020))
([80f182e](80f182e1af))
* use mutate context hook
([#1031](https://github.com/open-feature/js-sdk/issues/1031))
([ec3d967](ec3d967f8b))


### 🧹 Chore

* add js docs for context mutator hook
([#1045](https://github.com/open-feature/js-sdk/issues/1045))
([def3fe8](def3fe8daf))
* import type lint rule and fixes
([#1039](https://github.com/open-feature/js-sdk/issues/1039))
([01fcb93](01fcb933d2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-10-29 11:41:12 -04:00
Todd Baert 80f182e1af
feat: implement tracking as per spec (#1020)
📣 This was a draft for a while, but is now ready for review! 📣

This implements tracking as per spec, in the server, web, and react
SDKs.
I don't think the Angular or Nest SDKs need specific implementations,
but please advise (cc @luizgribeiro @lukas-reining).

Fixes: https://github.com/open-feature/js-sdk/issues/1033
Fixes: https://github.com/open-feature/js-sdk/issues/1034

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-10-29 13:46:08 +00:00
Todd Baert def3fe8daf
chore: add js docs for context mutator hook (#1045)
Minor refactors, but mostly adding js-doc after
https://github.com/open-feature/js-sdk/pull/1031.

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-10-17 15:09:25 -04:00
Will C. ec3d967f8b
feat: use mutate context hook (#1031)
context mutation hook

---------

Signed-off-by: Will C. <iam@willchou.dev>
Co-authored-by: Lukas Reining <lukas.reining@codecentric.de>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-10-17 12:15:26 -04:00
Todd Baert 01fcb933d2
chore: import type lint rule and fixes (#1039)
Inspired by [this
comment](https://github.com/open-feature/js-sdk/pull/1020#discussion_r1777829664)
I've added a lint rule to enforce `import type`, and some additional
package changes to add a `lint:fix`.

The only changes I made manually here is to add the lint rule, and the
package.json script. All the changes are auto-generated by the
`lint:fix`.

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-10-16 14:33:47 -04:00
Michael Beemer b8f9b4ebaf
feat: avoid re-resolving flags unaffected by a change event (#1024)
## This PR

- avoid re-resolving flags unaffected by a change event

### Notes

If the provider sends the change event payload, the React SDK uses the
list of change flags. If the list is missing or empty, all events are
triggered. This is a way to avoid sending unnecessary evaluation
telemetry data.

---------

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-10-01 14:15:18 -04:00
OpenFeature Bot e6adae04a5
chore(main): release react-sdk 0.4.6 (#1022)
🤖 I have created a release *beep* *boop*
---


##
[0.4.6](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.5...react-sdk-v0.4.6)
(2024-09-23)


### 🐛 Bug Fixes

* failure to re-render on changes
([#1021](https://github.com/open-feature/js-sdk/issues/1021))
([c927044](c927044c49))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-09-23 17:40:13 -04:00
Michael Beemer c927044c49
fix: failure to re-render on changes (#1021)
## This PR

- maintains a reference to the latest evaluation details.

### Notes

The change to optimize the rendering behavior was comparing a stale
value.

https://github.com/open-feature/js-sdk/pull/987

This PR adds a [mutable
ref](https://reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables)
that's updated every time the evaluation details are updated.

### Follow-up Tasks

This was manually tested. Unit tests will follow.

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2024-09-23 17:39:30 -04:00
OpenFeature Bot e017300b79
chore(main): release react-sdk 0.4.5 (#1000)
🤖 I have created a release *beep* *boop*
---


##
[0.4.5](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.4...react-sdk-v0.4.5)
(2024-09-04)


###  New Features

* **react:** prevent rerenders when value is unchanged
([#987](https://github.com/open-feature/js-sdk/issues/987))
([b7fc08e](b7fc08e27d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-09-04 19:20:33 +00:00
Michael Beemer b7fc08e27d
feat(react): prevent rerenders when value is unchanged (#987)
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2024-09-04 14:53:05 -04:00
OpenFeature Bot 05b14a9d14
chore(main): release react-sdk 0.4.4 (#986)
🤖 I have created a release *beep* *boop*
---


##
[0.4.4](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.3...react-sdk-v0.4.4)
(2024-08-28)


### 🧹 Chore

* move client/ dir to web/
([#991](https://github.com/open-feature/js-sdk/issues/991))
([df4e72e](df4e72eabc))


### 📚 Documentation

* **react:** update the error message
([#978](https://github.com/open-feature/js-sdk/issues/978))
([429c4ae](429c4ae941))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-08-28 09:09:55 -04:00
Todd Baert df4e72eabc
chore: move client/ dir to web/ (#991)
I've been meaning to do this for a while... it just renames the
`client/` dir to `web/`. I think this is better because there will be
less confusion around the OpenFeature client object (which has it's own
dirs) and because it's more consistent with the associated artifact name
"web-sdk".

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-08-28 12:11:52 +00:00
Michael Beemer 429c4ae941
docs(react): update the error message (#978)
## This PR

- updates the example error message

### Notes

The linter used by the documentation expects a language to be used on
all code fences.


https://github.com/open-feature/openfeature.dev/actions/runs/10449600501/job/28932244856?pr=592

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2024-08-26 13:23:00 -04:00
OpenFeature Bot 51d43230d9
chore(main): release react-sdk 0.4.3 (#981)
🤖 I have created a release *beep* *boop*
---


##
[0.4.3](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.2...react-sdk-v0.4.3)
(2024-08-22)


### 🐛 Bug Fixes

* race condition in test provider with suspense
([#980](https://github.com/open-feature/js-sdk/issues/980))
([0f187fe](0f187fe0b5))


### 🧹 Chore

* fix flaky test timing
([ad46ade](ad46ade143))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-08-22 15:22:56 -04:00
Todd Baert ad46ade143 chore: fix flaky test timing
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-08-22 15:15:42 -04:00
Todd Baert 0f187fe0b5
fix: race condition in test provider with suspense (#980)
Fixes an issues with the React `OpenFeatureTestProvider` where the
provider was not ready until the next event loop tick when the
`flagValueMap` was used.

Also removes the initialization in the client in-memory provider, since
it was only doing some un-needed validation inconsistent with the server
provider.

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-08-22 19:08:38 +00:00
OpenFeature Bot cb4e56ae80
chore(main): release react-sdk 0.4.2 (#974)
🤖 I have created a release *beep* *boop*
---


##
[0.4.2](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.1...react-sdk-v0.4.2)
(2024-07-29)


###  New Features

* add test provider
([#971](https://github.com/open-feature/js-sdk/issues/971))
([1c12d4d](1c12d4d548))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-07-29 14:12:27 -04:00
Todd Baert 1c12d4d548
feat: add test provider (#971)
Adds some testing utilities, specifically an
`<OpenFeatureTestProvider/>` react context provider.

See README for details.

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-07-29 17:52:59 +00:00
OpenFeature Bot d53e2eebe1
chore(main): release react-sdk 0.4.1 (#960)
🤖 I have created a release *beep* *boop*
---


##
[0.4.1](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.4.0...react-sdk-v0.4.1)
(2024-06-11)


###  New Features

* lower compilation target to es2015
([#957](https://github.com/open-feature/js-sdk/issues/957))
([c2d6c17](c2d6c1761a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-06-11 12:45:04 -04:00
Michael Beemer c2d6c1761a
feat: lower compilation target to es2015 (#957)
## This PR

- replace the es2022 error cause with a custom implementation
- lower compilation target from es2022 to es2015

### Related Issues

Fixes #956

### Notes

The tests pass, but I still want to manually build and test the outputs
in a real application to ensure everything works as expected.

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
2024-06-11 12:47:19 +00:00
OpenFeature Bot e9d3ebc3d8
chore(main): release react-sdk 0.4.0 (#942)
🤖 I have created a release *beep* *boop*
---


##
[0.4.0](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.3.4...react-sdk-v0.4.0)
(2024-05-13)


### ⚠ BREAKING CHANGES

* disable suspense by default, add suspense hooks
([#940](https://github.com/open-feature/js-sdk/issues/940))

###  New Features

* disable suspense by default, add suspense hooks
([#940](https://github.com/open-feature/js-sdk/issues/940))
([6bcef89](6bcef8977d))
* set context during provider init on web
([#919](https://github.com/open-feature/js-sdk/issues/919))
([7e6c1c6](7e6c1c6e70))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-05-13 17:41:58 -04:00
Todd Baert 6bcef8977d
feat!: disable suspense by default, add suspense hooks (#940)
This PR:

- inverts the suspense defaults (we now do not suspend by default, you
have to add `suspend:true` in options)
- adds `useSuspenseFlag` (analogous to `useSuspenseXxx`) in other
libraries, which behaves the same as `useFlag` with `{ suspend: true }`
- updates README (specifically encourages use use "query-style" hooks
over type-specific hooks
- adds `@experimental` jsdoc marker to all suspense options and hooks
- associated tests


Things to consider:

- I did not add `useSuspense{Type}FlagValue` and
`useSuspense{Type}FlagDetails` hooks; we could do this if we wanted, but
IMO these are already not the primary APIs we want to push users toward
in react - we want them to use the generic `useFlag` and
`useSuspenseFlag` which return the react query interfaces.

Fixes: https://github.com/open-feature/js-sdk/issues/933

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-05-13 19:08:10 +00:00
Michael Beemer 7e6c1c6e70
feat: set context during provider init on web (#919)
## This PR

- overloads the set provider methods to support defining context in the
web SDK
- updates the web sdk readme

## Related Issues

Fixes https://github.com/open-feature/js-sdk/issues/748

## Notes

I decided to only support setting context in the web SDK because it is
less valuable on the server and the expected behavior was less clear due
to `domains`.

The behavior may need to be spec'd out. An issue in the spec repo has
been created.
https://github.com/open-feature/spec/issues/219

---------

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-05-08 17:42:34 +00:00
OpenFeature Bot 6dd558ee61
chore(main): release react-sdk 0.3.4 (#923)
🤖 I have created a release *beep* *boop*
---


##
[0.3.4](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.3.3...react-sdk-v0.3.4)
(2024-05-01)


### 🐛 Bug Fixes

* delayed suspense causes "flicker"
([#921](https://github.com/open-feature/js-sdk/issues/921))
([4bce2a0](4bce2a0f1a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-05-01 09:53:21 -04:00
Rowan Heptinstall ad8898e8a9
test: add testing for HookFlagQuery (#922)
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## This PR
<!-- add the description of the PR here -->

- introduces tests for `HookFlagQuery`

### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->

Resolves #915 

### Notes
Placed these tests within `evaluation.spec.tsx`, happy to move them into
their own file if more appropriate

---------

Signed-off-by: Rowan Heptinstall <rowanheptinstall1@gmail.com>
Signed-off-by: Rowan Heptinstall <155630047+ro1hep@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-05-01 13:17:11 +00:00
Tommy Josépovic 4bce2a0f1a
fix: delayed suspense causes "flicker" (#921)
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## This PR
<!-- add the description of the PR here -->

- Add an internal `useOpenFeatureClientStatus()` function to make it
slightly easier to keep track of the state of the current Client, and
know when to suspend or not.

- Replaces the `suspend()` function with a `suspendUntilReady()`
function. The `suspendUntilReady()` function fires immediatly during the
first render or when the component cannot render due to the client
having changed status.

- Put the Client status and the feature flag details inside React
states. This is required to make APIs like `startTransition` work
properly with the library

### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->

Fixes #920

### Notes
<!-- any additional notes for this PR -->

### Follow-up Tasks

- [x] Add more tests. Suspense and Transitions are very tricky. While
these changes don't seem to have broken any existing tests, we should
add new tests to make sure Suspense and Transitions continue to work
properly in the future.

- [ ] ~I think there might still be some reactivity issues with some
parts of the codebase. The client returned by `useOpenFeatureClient()`
didn't seem to update properly when the client changed, which made
`useOpenFeatureClientStatus()` not update properly.~ Out of the scope of
this PR

### How to test
<!-- if applicable, add testing instructions under this section -->

I built the application with `npm build`, then `npm pack`. I used the
modified code on a local project to see if it fixed the issues.

I built projects in CodeSanbox that demonstrate the issues.

For Suspense:
https://codesandbox.io/embed/openfeature-suspense-bug-5j7yll?fontsize=14&hidenavigation=1&theme=dark

For Transitions:
https://codesandbox.io/embed/openfeature-suspense-bug-forked-lqhyf3?fontsize=14&hidenavigation=1&theme=dark

---------

Signed-off-by: Tommy Josépovic <tommy.josepovic@gsoft.com>
2024-05-01 13:00:32 +00:00
OpenFeature Bot 86a9230add
chore(main): release react-sdk 0.3.3 (#917)
🤖 I have created a release *beep* *boop*
---


##
[0.3.3](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.3.2...react-sdk-v0.3.3)
(2024-04-23)


### 🐛 Bug Fixes

* invocation hooks not called
([#916](https://github.com/open-feature/js-sdk/issues/916))
([2f77738](2f77738090))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-04-23 15:07:03 -04:00
Todd Baert 2f77738090
fix: invocation hooks not called (#916)
- fixes issue where invocation hooks were not called in the React SDK
- adds associated tests 

Fixes: https://github.com/open-feature/js-sdk/issues/914

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-04-23 16:55:30 +00:00
OpenFeature Bot 5e28dbb81a
chore(main): release react-sdk 0.3.2 (#909)
🤖 I have created a release *beep* *boop*
---


##
[0.3.2](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.3.2-experimental...react-sdk-v0.3.2)
(2024-04-18)


### 🧹 Chore

* remove pre-release, update readme
([#908](https://github.com/open-feature/js-sdk/issues/908))
([2532379](2532379f2e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
2024-04-18 16:35:29 +00:00
Todd Baert 2532379f2e
chore: remove pre-release, update readme (#908)
- prompts a release of a non-experimental react-sdk
- updates README to point to React and NestJS SDKs
- removes version of peer deps from README (too brittle, point users to
`package.json`)
- adds an FAQ question

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-04-17 20:46:03 +00:00
OpenFeature Bot ba1be5cc81
chore(main): release react-sdk 0.3.2-experimental (#907)
🤖 I have created a release *beep* *boop*
---


##
[0.3.2-experimental](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.3.1-experimental...react-sdk-v0.3.2-experimental)
(2024-04-11)


### 🐛 Bug Fixes

* re-render w/ useWhenProviderReady, add tests
([#901](https://github.com/open-feature/js-sdk/issues/901))
([0f2094e](0f2094e236))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-04-12 07:56:40 -04:00
Todd Baert 0f2094e236
fix: re-render w/ useWhenProviderReady, add tests (#901)
This PR:

- brings react-sdk test coverage from 0% to ~95%
  - adds DOM-based testing (tests based on asserting DOM entity states)
    - tests for query-style, basic, and detailed evaluation APIs
- tests for suspense functionality and re-rendering on context change
  - tests for some util functions and hooks
  - `renderHook` tests for non suspending hooks
- fixes a bug where `useWhenProviderReady` didn't cause re-render after
the provider is ready if suspense wasn't used (leading to an out-of-date
return value for provider readiness)


![image](https://github.com/open-feature/js-sdk/assets/25272906/e8ee420f-0167-4048-94e3-53176bd883b9)

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-04-11 17:41:13 +00:00
OpenFeature Bot 240a46165d
chore(main): release react-sdk 0.3.1-experimental (#906)
🤖 I have created a release *beep* *boop*
---


##
[0.3.1-experimental](https://github.com/open-feature/js-sdk/compare/react-sdk-v0.3.0-experimental...react-sdk-v0.3.1-experimental)
(2024-04-09)


### 🐛 Bug Fixes

* default options (re-renders not firing by default)
([#905](https://github.com/open-feature/js-sdk/issues/905))
([a85e723](a85e72333f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
2024-04-09 16:20:54 -04:00
Todd Baert a85e72333f
fix: default options (re-renders not firing by default) (#905)
When I was adding the general `suspend` option as @lukas-reining
suggested (a way to enable/disable all suspense features) I broke the
default options. I found this writing tests in a different branch.

Tests for the entire SDK including this are incoming shortly (today),
but this is a fix for the issue.

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2024-04-09 16:03:06 -04:00