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

[Bug]: NaN cannot be returned on iOS #7265

Closed
1 of 3 tasks
robingenz opened this issue Feb 17, 2024 · 4 comments
Closed
1 of 3 tasks

[Bug]: NaN cannot be returned on iOS #7265

robingenz opened this issue Feb 17, 2024 · 4 comments
Labels

Comments

@robingenz
Copy link
Contributor

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 5.7.0
@capacitor/core: 5.7.0
@capacitor/android: 5.7.0
@capacitor/ios: 5.7.0

Installed Dependencies:

@capacitor/cli: 5.4.2
@capacitor/android: 5.4.2
@capacitor/core: 5.4.2
@capacitor/ios: 5.4.2

[success] iOS looking great! 👌
[success] Android looking great! 👌

Other API Details

No response

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

The Capacitor Firebase Firestore must be able to receive and return a NaN value. Under iOS it is already possible to pass a NaN value to a plugin. Unfortunately, there are problems with returning the value, see the following example:

@objc func getDocument(_ call: CAPPluginCall) {
    call.resolve([
        "test": Double.nan
    ])
}

grafik

Capacitor returns an empty object. Not only is the NaN value missing, but all other keys would also be missing.

Expected Behavior

It should be possible to return a NaN value from a plugin.

Project Reproduction

https://github.com/robingenz/capacitor-firebase-plugin-demo/blob/main/src/app/modules/firebase-firestore/firebase-firestore.page.ts

Additional Information

No response

@markemer
Copy link
Member

This is always going to behave strangely since NaN is not supported in JSON: RFC-4627 Section 6

We use JSON.stringify type functions to pass data back and forth between the bridge and the native platforms and they have a variety of undefined behavior with NaN or Infinite IEEE-754 values.

@markemer markemer closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2024
@robingenz
Copy link
Contributor Author

@markemer Thank you for your response!

A possible solution would be to replace NaN with a custom JSON object before passing it to the bridge and restore it on the native side.

Example:

{
	"_cap_type": "nan"
}

I have planned the same, for example, to support Cloud Firestore field values (see capawesome-team/capacitor-firebase#443), except that the implementation there is located in the plugin and not in the Capacitor core.
With NaN, however, this implementation must be placed in the Capacitor core, as this value is not plugin-specific and can also be returned.

Could you please discuss this again in the team?

@theproducer
Copy link
Contributor

@robingenz Hello!

Yes, a similiar approach was my initial idea for handling this, but Mark metioned, we use JSON parsing/encoding for communicating back and forth, and we decided just to stick with what is natively supported in JSON, at least for now. There are ideas / opportunities in the future for us to be able to accomidate this however.

Copy link

ionitron-bot bot commented Mar 27, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants