react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

🐛 [@react-native-firebase/functions] Missing `stream` implementation for `httpsCallable` functions

Open harveyappleton opened this issue 11 months ago • 15 comments

Hey amazing invertase team! Happy new year!

In Dec 2024, a PR was merged into firebase-js-sdk that allows you to stream responses from Firebase functions which is awesome! I've tried it out on web and it works wonderfully. Would be awesome if this could be implemented in RN Firebase Functions!!! :D

harveyappleton avatar Jan 04 '25 21:01 harveyappleton

Neat, wasn't aware of that work.

I believe we'll need underlying SDK support prior to us being able to do anything at this layer above them

iOS: https://github.com/firebase/firebase-ios-sdk/pull/14290 Android: https://github.com/firebase/firebase-android-sdk/pull/6602

After that we'll have a fair bit of work here to wrap them and present them in a manner compatible with firebase-js-sdk (or we'd happily accept a PR of course...)

The only thing I can think of in the meantime is that you can actually use the firebase-js-sdk alongside react-native-firebase if you like. It is bundled with react-native-firebase as it is used as a fallback for "other" platform support already internally here. You'll have to initialize an app manually after react-native-app boot just like you do on web, and if you use AppCheck you'll have to set the firebase-js-sdk functions headers with it after fetching it from react-native-firebase/app-check, similar with auth - but those headers shouldn't be too hard to set ?

mikehardy avatar Jan 04 '25 23:01 mikehardy

I looked into using firebase-js-sdk alongside, but I think the issue is that on React Native, the fetch implementation doesn't support ReadStream. Seems like a common problem. However I found that Expo SDK 52 provides a fetch implementation that is winter cg compliant that supports streaming, so I'm currently updating my app to use that instead and will just manually stream from the firebase function I think :) I can get the Bearer token from firebase auth using getIdToken() so should be all good to go 🙏 would be awesome if the RN firebase supported it but I understand its probably a big chunk of work.

harveyappleton avatar Jan 05 '25 15:01 harveyappleton

Is a big chunk of work to support it here but most importantly we can't do anything not provided by the underling native android and iOS SDKs, so we are necessarily blocked on them regardless.

Very nifty that it looks like it'll be possible to "weld together" the firebase-js-sdk library support for it while still using react-native-firebase for it's native-only stuff though

mikehardy avatar Jan 05 '25 20:01 mikehardy

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Feb 02 '25 20:02 github-actions[bot]

Still requires attention

harveyappleton avatar Feb 08 '25 13:02 harveyappleton

@harveyappleton there's nothing we can do here, I just paid attention to it but it unfortunately wasn't attention well spent. Without upstream support there is nothing we can do, and it hasn't landed there as far as I know.

You might look at the VertexAI implementation that we'll be landing soon though - it was able to use react-native fetch plus some polyfills to get readable stream support using javascript. That strategy can work:

https://github.com/invertase/react-native-firebase/pull/8236/files#diff-f22d3ccf7d705193a63381ca0d16187ba37c273cfaa52cbaac399f237f3e9278

mikehardy avatar Feb 08 '25 14:02 mikehardy

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Mar 08 '25 14:03 github-actions[bot]

Streaming callable functions appears to have landed in firebase-android-sdk (33.11.0) and firebase-ios-sdk (11.10.0) now, this should be possible to implement now

mikehardy avatar Mar 21 '25 14:03 mikehardy

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Apr 18 '25 14:04 github-actions[bot]

@mikehardy Hi, is there have any plan for this?

lookis avatar Jun 03 '25 08:06 lookis

can we have a RN streaming callable yet?

tion8888 avatar Oct 31 '25 05:10 tion8888

possibly yes - I'll reopen, in addition to SDK support, react-native itself has a lot of issues with streams because the underlying implementations are incomplete upstream in react-native. However we've gotten pretty good at polyfilling them with success here in our implementation of remote-config realtime updates and the AI session streaming so there should be no technical reason we can't (as long as the polyfills in those packages are adopted). Open to PRs of course, but this is valid for the issue backlog either way

mikehardy avatar Oct 31 '25 11:10 mikehardy

that would be amazing @mikehardy! this is sorely needed for LLM streaming apps. The workarounds with onRequest and Xhr feel so 2008.

Related, (but not critical if RN starts to support Streaming Callables) is that fetch in RN also does not support ReadableStream/response.body.getReader() so there's workarounds on top of workarounds we're resorting to today.

Would be happy to help test! tysm!

tion8888 avatar Oct 31 '25 15:10 tion8888

Check the polyfill file and related deps in our ai and remote-config package for a readable stream fix that works for us

mikehardy avatar Oct 31 '25 16:10 mikehardy

+1

cchafik avatar Nov 12 '25 18:11 cchafik

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Dec 10 '25 18:12 github-actions[bot]

+1

TomasBruno1 avatar Dec 10 '25 18:12 TomasBruno1

There is a streaming functions PR in the works

  • #8772

mikehardy avatar Dec 10 '25 19:12 mikehardy