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

Optional suspense #255

Merged
merged 28 commits into from
Nov 18, 2020
Merged

Optional suspense #255

merged 28 commits into from
Nov 18, 2020

Conversation

jhuleatt
Copy link
Collaborator

@jhuleatt jhuleatt commented May 13, 2020

What's happening?

This is a proposed API change that makes it easier to use ReactFire without enabling experimental React features (Suspense & Concurrent Mode).

"Suspense Mode" will be settable in FirebaseAppProvider (in which case it will automatically apply to all children of FirebaseAppProvider), or in individual calls as part of ReactFireOptions.

<FirebaseAppProvider firebaseConfig={config} suspense={true}>
    <App />
</FirebaseAppProvider>

If you don't set suspense={true} in FirebaseAppProvider, it will default to false.

Now that Suspense won't necessarily be handling loading states, each hook will return more information about its status:

export interface ObservableStatus<T> {
  status:
    | 'loading' // waiting for first value from observable
    | 'error'
    | 'success'; // has received at least one value
  hasEmitted: boolean; // has received at least one value
  isComplete: boolean; // observable has triggered onComplete event
  data: T; // latest data from observable
  error: Error | undefined;
  firstValuePromise: Promise<void>; // promise that resolves after first emit from observable
}

Status

  • Make API changes to core library
  • Update tests for new API, and add new tests that don't use Suspense
  • Make a sample that works without Suspense
  • Ensure all Suspense samples and tests still work
  • Update docs with new API:
    • README
    • Guide (just added a disclaimer that samples are for Concurrent Mode)
    • Quickstart (just added a disclaimer that samples are for Concurrent Mode)
    • Reference

@jhuleatt jhuleatt marked this pull request as draft May 13, 2020 19:20
@jhuleatt jhuleatt marked this pull request as ready for review May 27, 2020 20:42
@davideast davideast marked this pull request as ready for review May 27, 2020 20:42
@jhuleatt jhuleatt requested a review from jamesdaniels May 27, 2020 20:42
@zaccharles
Copy link

Thanks for the hard work, is there anything I can do to help get this across the line?

@praneybehl
Copy link

praneybehl commented Jul 4, 2020

Seems like one of the pipelines is stuck since a few months. Is this PR dead?

@kantmichel
Copy link

i'd be very keen on using this in the current stable react version. Any idea's on when this is being merged?

@mastef
Copy link

mastef commented Sep 2, 2020

@jhuleatt @jamesdaniels Any chance this proposal may make it any time soon into ReactFire? Since it was mentioned in #260 and there's great interest in using ReactFire with the stable builds of React.

Thank you for your work on this!

@jhuleatt
Copy link
Collaborator Author

Hey there, apologies for the long silence on this. We're working on reviving this PR, and I've just pushed the latest updates.

Examples of the new api can be found here: https://github.com/FirebaseExtended/reactfire/tree/optional-suspense/example/withoutSuspense

If you want to pull this branch yourself and try things out, pull it then run:

In one terminal:

yarn
yarn start

In a second terminal:

cd example
yarn
yarn start

src/database.tsx Outdated Show resolved Hide resolved
@no-1ne
Copy link

no-1ne commented Nov 6, 2020

Hello folks,
Thank you for this, Looking forward to being able to use it in production builds of react.

@jhuleatt jhuleatt self-assigned this Nov 18, 2020
@jhuleatt jhuleatt merged commit 5ba5e09 into master Nov 18, 2020
@jhuleatt jhuleatt deleted the optional-suspense branch November 18, 2020 20:46
@FirebaseExtended FirebaseExtended locked and limited conversation to collaborators Dec 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants