Skip to content

React Native build does not maintain arrow functions and causes error with AsyncStorage #1580

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

Closed
4 tasks done
swittk opened this issue Oct 22, 2022 · 2 comments · Fixed by #1587
Closed
4 tasks done
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@swittk
Copy link
Contributor

swittk commented Oct 22, 2022

New Issue Checklist

Issue Description

When using the AsyncStorage backend for react-native, you would get Unhandled promise rejection: TypeError: this.getAsyncStorage is not a function. when trying to save objects.

Inspecting the distribution file node_modules/parse/lib/react-native/StorageController.react-native.js shows that all arrow functions have been transformed into regular functions, causing the this context to become ones of the callback functions and making everything break.

Replacing all the unnamed functions with arrow functions as originally written in the source restores the same, functioning behaviour.

This appears to be a problem with the babel transpiler during the publish process (the file clearly has _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault") at the top).

Steps to reproduce

  • Install [email protected] into a react native project.
  • Configure Parse to use AsyncStorage backend
import AsyncStorage from '@react-native-async-storage/async-storage';
Parse.setAsyncStorage(AsyncStorage);
  • Try creating a new Parse.Object
  • Call await object.save() or await object.saveEventually() on the object

Actual Outcome

  • [Unhandled promise rejection: TypeError: this.getAsyncStorage is not a function. (In 'this.getAsyncStorage()', 'this.getAsyncStorage' is undefined)]
  • This can be fixed by manually going into the node_modules/parse/lib/react-native/StorageController.react-native.js and replacing all the unnamed functions with arrow functions as originally written in the source restores the same, functioning behaviour.

Expected Outcome

  • The object gets saved normally.

Environment

Server

  • Parse Server version: 5.2.8
  • Operating system: Mac OS 12.4
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local host

Client

  • Parse JS SDK version: 3.5.0-alpha.6

Logs

[Unhandled promise rejection: TypeError: this.getAsyncStorage is not a function. (In 'this.getAsyncStorage()', 'this.getAsyncStorage' is undefined)]
at node_modules/parse/lib/react-native/StorageController.react-native.js:12:26 in Promise$argument_0
at node_modules/parse/lib/react-native/StorageController.react-native.js:11:22 in getItemAsync
at node_modules/parse/lib/react-native/Storage.js:24:36 in getItemAsync
at node_modules/parse/lib/react-native/EventuallyQueue.js:435:40 in load
at node_modules/parse/lib/react-native/EventuallyQueue.js:449:56 in _regeneratorRuntime.async$argument_0
at node_modules/parse/lib/react-native/EventuallyQueue.js:96:20 in tryCatch
at node_modules/parse/lib/react-native/EventuallyQueue.js:76:31 in <anonymous>
at node_modules/parse/lib/react-native/EventuallyQueue.js:96:20 in tryCatch
at node_modules/parse/lib/react-native/EventuallyQueue.js:134:27 in invoke
at node_modules/parse/lib/react-native/EventuallyQueue.js:158:16 in PromiseImpl$argument_0
at node_modules/parse/lib/react-native/EventuallyQueue.js:157:30 in callInvokeWithMethodAndArg
at node_modules/parse/lib/react-native/EventuallyQueue.js:162:154 in _invoke
at node_modules/parse/lib/react-native/EventuallyQueue.js:248:66 in exports.async
at node_modules/parse/lib/react-native/EventuallyQueue.js:438:38 in getQueue
at node_modules/parse/lib/react-native/EventuallyQueue.js:525:60 in _regeneratorRuntime.async$argument_0
at node_modules/parse/lib/react-native/EventuallyQueue.js:96:20 in tryCatch
at node_modules/parse/lib/react-native/EventuallyQueue.js:76:31 in <anonymous>
at node_modules/parse/lib/react-native/EventuallyQueue.js:96:20 in tryCatch
at node_modules/parse/lib/react-native/EventuallyQueue.js:134:27 in invoke
at node_modules/parse/lib/react-native/EventuallyQueue.js:158:16 in PromiseImpl$argument_0
at node_modules/parse/lib/react-native/EventuallyQueue.js:157:30 in callInvokeWithMethodAndArg
at node_modules/parse/lib/react-native/EventuallyQueue.js:162:154 in _invoke
at node_modules/parse/lib/react-native/EventuallyQueue.js:248:66 in exports.async
at node_modules/parse/lib/react-native/EventuallyQueue.js:520:38 in length
@parse-github-assistant
Copy link

parse-github-assistant bot commented Oct 22, 2022

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Oct 22, 2022
@swittk
Copy link
Contributor Author

swittk commented Oct 23, 2022

Screen Shot 2565-10-23 at 07 24 01

(Image for reference) The right window shows the current 3.5.0-alpha.6 failing build, while the left window shows the current stable version (3.4.4) with the arrow functions transformed appropriately with their `this` contexts.

I have compared the distribution files on NPM and found that the change occurred with the 3.5.0-alpha.4 release (3.5.0-alpha.3 has the correct this context transformations).

@mtrezza mtrezza changed the title React Native build does not maintain arrow functions and causes error with AsyncStorage. React Native build does not maintain arrow functions and causes error with AsyncStorage Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
2 participants