Skip to content

feat: add polyfill for react use hook #1157

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

Merged
merged 5 commits into from
Apr 10, 2025
Merged

Conversation

beeme1mr
Copy link
Member

@beeme1mr beeme1mr commented Feb 26, 2025

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.

Copy link
Member

@lukas-reining lukas-reining left a comment

Choose a reason for hiding this comment

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

This generally looks good to me!
I left one concern that I am not really sure about.

Copy link

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

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

Don't see anything obviously violating here, but I haven't done the due diligence to run it locally yet

@beeme1mr beeme1mr marked this pull request as ready for review March 6, 2025 20:49
@beeme1mr beeme1mr requested a review from a team as a code owner March 6, 2025 20:49
@beeme1mr beeme1mr changed the title feat: add support for suspense flags in next.js feat: add support for building Next.JS apps that use suspending flags. Mar 6, 2025
@beeme1mr beeme1mr changed the title feat: add support for building Next.JS apps that use suspending flags. feat: add polyfill for react use hook Apr 10, 2025
Co-authored-by: Todd Baert <[email protected]>
Signed-off-by: Michael Beemer <[email protected]>
@beeme1mr beeme1mr requested a review from a team as a code owner April 10, 2025 11:42
@lukas-reining lukas-reining requested a review from toddbaert April 10, 2025 11:48
Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

I tested this in the react demo app and it worked as expected.

@toddbaert toddbaert enabled auto-merge April 10, 2025 12:06
@toddbaert toddbaert added this pull request to the merge queue Apr 10, 2025
Merged via the queue into main with commit 5afe61f Apr 10, 2025
9 checks passed
@toddbaert toddbaert deleted the improve-react-suspense branch April 10, 2025 12:08
github-merge-queue bot pushed a commit that referenced this pull request Apr 14, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](react-sdk-v0.4.11...react-sdk-v1.0.0)
(2025-04-14)


### ✨ New Features

* add polyfill for react use hook
([#1157](#1157))
([5afe61f](5afe61f))
* add support for abort controllers to event handlers
([#1151](#1151))
([6a22483](6a22483))

---
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 <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Todd Baert <[email protected]>
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.

4 participants