Closed alexvcasillas closed 1 week ago
Thanks @alexvcasillas! I'll take a look later this week or over the weekend.
I have a suspicion this isn't related to MST, but this issue will help me improve my confidence in that assessment.
Thanks @alexvcasillas! I'll take a look later this week or over the weekend.
I have a suspicion this isn't related to MST, but this issue will help me improve my confidence in that assessment.
Thank you, Tyler! I'm investigating and researching about it so I can release the game so I'll come back here to share my findings :)
Hey @alexvcasillas - reading through your code now and my first question is: do you have any try/catch
logic on the afterCreate
hook for User
?
yield
can throw, and if you're not catching it, I don't think either of your if / else
statements will evaluate. That might be the culprit. Especially if you're getting some kind of Apple credentials and seeing failures in production but not development.
Consider this code, where we throw from an async function and neither branch evaluates:
import { flow, types } from "mobx-state-tree";
async function getStoredCredentials() {
throw new Error("Did not work");
}
(async function () {
const User = types
.model("User", {
name: "Default value",
})
.actions((self) => ({
afterCreate: flow(function* () {
const credentials = yield getStoredCredentials();
if (credentials) {
self.name = "It worked";
} else {
self.name = "Call worked but was falsy";
}
}),
}));
const user = User.create();
// This will log out "Default Value" - neither branch evaluated
console.log(user.name);
})();
If you're not catching errors, maybe start there and do some logging in production.
I'll keep thinking and try to build a better reproduction or test case later this week or next, but hopefully this is helpful.
Hey @alexvcasillas - reading through your code now and my first question is: do you have any
try/catch
logic on theafterCreate
hook forUser
?
yield
can throw, and if you're not catching it, I don't think either of yourif / else
statements will evaluate. That might be the culprit. Especially if you're getting some kind of Apple credentials and seeing failures in production but not development.Consider this code, where we throw from an async function and neither branch evaluates:
import { flow, types } from "mobx-state-tree"; async function getStoredCredentials() { throw new Error("Did not work"); } (async function () { const User = types .model("User", { name: "Default value", }) .actions((self) => ({ afterCreate: flow(function* () { const credentials = yield getStoredCredentials(); if (credentials) { self.name = "It worked"; } else { self.name = "Call worked but was falsy"; } }), })); const user = User.create(); // This will log out "Default Value" - neither branch evaluated console.log(user.name); })();
If you're not catching errors, maybe start there and do some logging in production.
I'll keep thinking and try to build a better reproduction or test case later this week or next, but hopefully this is helpful.
Hey @coolsoftwaretyler I don't have any try-catch blocks on the afterCreate
logic as most of the asynchronous calls are API calls or Secure Storage calls. I've upgraded to the latest MST 7.0 and upgraded some other dependencies and the app now works in the preview but I'm hesitant to consider this done. I'll wrap the async calls within try-catch to try to handle everything properly just in case it's something that's throwing and I'm not aware of
@alexvcasillas - yeah I think it makes sense to at least try and eliminate it as a possibility. While you're adding exception handling I might recommend some logging in the function as well to really see what behavior it's exhibiting in production.
Alex and I spoke in a DM and he said the root of this issue might be with Stripe. Closing.
Hey @coolsoftwaretyler , as we spoke in the X thread and by your suggestion I'm opening up this issue on the MST repo though it might not even be related to MST itself, but I hope that you can help me try to catch up what's happening 🤔
I have the following
user.store.ts
getStoredAppleCredentials
is just a wrapper for a call toawait SecureStore.getValueFor
and the same forgetStoredGoogleCredentials
I have omitted most of the actions and views for the sake of the example.
Then I have this
stats.store.ts
Again some actions and views have been omitted for the sake of the example.
When the app launches, I use in one of my observer components the
useUser()
hook, which as there's no session stored that can be retrieved from thegetStoredAppleCredentials
andgetStoredGoogleCredentials
the flow goes into theelse
which does:But none of these are actually created and therefore they're using the default
null
as per the type definition on theUser
model.The issue that I'm facing here is that this actually works in a development environment as the
GamesPlayed.create()
,Stats.create()
, andAchievements.create()
return their respective default values that are set in their respective models.I'm starting to think that this might be related to something along the build process with
MMKV
or even after introducing Sentry but since the code that does not get executed lives within MST it could also mean that it's been treated somehow differently when build with EAS for the preview environment 🤔