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

App stops executing next lines of code after network requests #1860

Closed
ibrahimelaradi opened this issue Jan 12, 2022 · 5 comments · Fixed by #1906
Closed

App stops executing next lines of code after network requests #1860

ibrahimelaradi opened this issue Jan 12, 2022 · 5 comments · Fixed by #1906
Labels

Comments

@ibrahimelaradi
Copy link

What's going on?

I'm waiting for network requests to finish before change the state of the app using mobx actions, I'm using generator functions as described in here

Here's a screenshot of logs from Reactotron, there should be a log after the API response that shows the state change
reactotron

Action:

.actions((self) => ({
  // ...
  signIn: flow(function* (form: CustomerSigninForm) {
    const api = self.environment.apis.guest
    const signinResult = yield api.signinAsCustomer(form) // <= code stops executing here

    // state change (saving token, fetching user details, etc

  }),
  // ...
}))

API method:

export class GuestApi extends Api {
  // client config, other methods
  async signinAsCustomer(form: CustomerSigninForm): Promise<SigninCustomerResult> {
    const url = this.base + "/integration/customer/token"
    const params = mapToCustomerSigninRequest(form)
    const response = await this.apisauce.post<string>(url, params) // <-- Code lines after this line don't execute
    if (!response.ok) {
      return getGeneralApiProblem(response) || { kind: "bad-data" }
    }
    return { kind: "ok", token: response.data }
  }
}

I'm experiencing this issue with both Android and iOS, however on Android, if I turn off DEV from cmd + M > Settings and reload the app it works perfectly fine

I tried running it with minification enabled and the issue still persists, am I doing something wrong?


Steps to reproduce

Will create a reproduction repo if no one has faced this issue before


npx ignite-cli doctor results:

doctor

@markrickert
Copy link
Member

Hey @ibrahimelaradi, sorry youre experiencing this. Is your component that is observing the mobx properties wrapped in the observer() function from mobx-react-lite?

For example, this won't update:

const MyComponent = () => {
  const stores = useStores();
  return (
    <Text>{stores.someStore.observedValue}</Text>
  )
}

...but this WILL:

const MyComponent = observer(() => {
  const stores = useStores();
  return (
    <Text>{stores.someStore.observedValue}</Text>
  )
})

@ibrahimelaradi
Copy link
Author

Hey @markrickert, all the files I'm using are generated using the CLI and they are by default wrapped inside of observer(), also it is worth mentioning that I've tried looking at the state tab of Reactotron and no state change has been recorded after receiving the network response

@carlosa54
Copy link
Contributor

Hi @ibrahimelaradi out of curiosity can you remove/comment out the <ToggleStorybook> component in app.tsx and see if it works?

<ToggleStorybook>
<RootStoreProvider value={rootStore}>
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<ErrorBoundary catchErrors={"always"}>
<AppNavigator
initialState={initialNavigationState}
onStateChange={onNavigationStateChange}
/>
</ErrorBoundary>
</SafeAreaProvider>
</RootStoreProvider>
</ToggleStorybook>

Just in case I had a similar issue and I ended up fixing it by refactoring the file below to use ES6 import instead

setStorybookUIRoot(() => require("./storybook").StorybookUIRoot)

@ibrahimelaradi
Copy link
Author

Hello @carlosa54, I commented out the wrapper and it worked fine, I'll refactor toggle-storybook.tsx to use ES6 import
Thank you!

infinitered-circleci pushed a commit that referenced this issue Mar 1, 2022
## [7.10.6](v7.10.5...v7.10.6) (2022-03-01)

### Bug Fixes

* **storybook:** Adds patch for storybook/addons to resolve promise bug ([#1906](#1906) by [@dannyhw](https://github.com/dannyhw)) ([0beee77](0beee77)), closes [#1860](#1860) [#1826](#1826) [#1769](#1769)
@infinitered-circleci
Copy link

🎉 This issue has been resolved in version 7.10.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants