pb + expo (react-native) + react-native-sse : EventSource connect took too long
RepComm opened this issue · comments
At this point I've tried using any polyfill I can get my hands on, the most success I've had is getting to EventSource connect took too long.
try {
result = await db.ctx?.collection("users").authWithOAuth2({
provider: this.props.provider,
urlCallback: (url)=>{
console.log("URL", url);
Linking.openURL(url).catch((err)=>{
console.error("Failed to open oauth url", err);
});
}
});
} catch (ex: any) {
let keys = Object.keys(ex);
let obj = {} as any;
for (let key of keys) {
obj[key] = ex[key];
}
console.log(obj);
if (this.props.onIssue) {
this.props.onIssue(`Couldn't perform OAuth: ${ex}`);
// return;
}
throw ex;
}
LOG {"isAbort": false, "name": "ClientResponseError 0", "originalError": [Error: EventSource connect took too long.], "response": {}, "status": 0, "url": ""}
WARN Couldn't perform OAuth: ClientResponseError 0: Something went wrong while processing your request.
As other similar issues, urlCallback doesn't seem to get called at all and doesn't console log.
Assuming this is a facebook Flipper thing:
I do not have the ability to change any java code as I'd have to eject the expo app to be raw react-native android project,
which kind of defeats the reason for using expo in the first place.
I tried expo's --no-dev flag hoping it would resemble react-native's --variant=release to no avail
I don't know why react-native has such a huge problem with EventSource, but it seems like its WAY more trouble than it's worth.
I'm not even trying to do realtime yet, I can't even fetch users full list but I'm installing server side events related polyfills.
Is there still a plan to migrate away from EventSource as a dependency?
I don't think I have any more options at this point other than just writing my own JS SDK or EventSource system dependency, and even then I'm not sure I wouldn't have the exact same issues other libs are having.
Update, I ran eas build to generate an android build and viewed it from expo snack on my android device, and the OAuth does redirect to my browser properly, though I do have device_id and device_name not setup for private IP redirect URI, but I can fix that later in the google dev console.
urlCallback does get fired properly in this state of things.
I think that probably confirms it as a flipper issue..?
I tried running NO_FLIPPER=1 && expo start
before this to no effect.
Unfortunately creating a build every time is not a valid workaround (even just due to time it takes to build in the cloud).
I will continue to work on this and update here. Dumb problems dumb solutions.
Edit- I used a DNS entry on one of my dev sites to setup google oauth redirect to a local IP and everything seems to be working with the android production build, so its purely a development issue. At least I know that the EventSource polyfill does work in some cases. Now I just have to figure out how to it with regular dev setup.
I don't fully understand the above description but you can check the discussion in pocketbase/pocketbase#2484 as it seems similar to your error.
I'm closing the issue for now as I don't think this is JS SDK related but feel free to let me know if you stumble on something else.
I managed to run expo metro (hot module reloading) in prod mode via:
npx expo start --no-dev
And this does not have the issue of EventSource timing out.
Not idea for debugging, but I'll take what I can get for now.
Thanks for your time even looking at this! I'll leave this answer here for anyone else trying to use expo with pocketbase.
Edit-
It worked for about 1 minute until npx expo start --no-dev
started caching things...
I added a console.log("Happens") that only is being triggered when I don't use --no-dev
but doesn't when I do.
It looks like without some kind of serious intervention I cannot use pocketbase with expo, and I think that is really just super silly.
@RepComm Did you check the above linked discussion and at the stackoverflow suggestion in https://stackoverflow.com/questions/69235694/react-native-cant-connect-to-sse-in-android/69235695#answer-69235695?
Several users reported that it works for them.
Note that technically the JS SDK doesn't have any dependencies. It relies only on native interfaces like fetch
and EventSource
. There are plans to reimplement eventually the EventSource
interface with raw fetch
streams to avoid the need of a polyfill for node-like environments but it is left aside for now because the last time I checked the fetch
implementation in React Native didn't support streams.