Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

IE 11 serialization problem #130

Closed
halcwb opened this issue Mar 1, 2019 · 7 comments
Closed

IE 11 serialization problem #130

halcwb opened this issue Mar 1, 2019 · 7 comments

Comments

@halcwb
Copy link

halcwb commented Mar 1, 2019

When trying to serialize an object like:

["PatientMsg",["Calculate",{"Age":{"Years":6,"Months":0,"Weeks":0,"Days":0},"Weight":{"Estimated":15,"Measured":15},"Height":{"Estimated":98,"Measured":0}}]]

in IE, what is created is:

["PatientMsg",["Calculate",[]]]

So the object in the discriminated union is not serialized in IE 11.

@MangelMaxime
Copy link
Owner

Hello @halcwb,

Do you have a warning/error in the console?

Are you using auto or manual coders?

Could you please provide reproduction code?

  • Domain types
  • Decoders/Encoders used

@halcwb
Copy link
Author

halcwb commented Mar 1, 2019

Hello @MangelMaxime

This is the code I use to send a request using Thoth encoding:

    let post req =
        let decode = Decode.Auto.unsafeFromString<Response Option>
        promise { let! res = postRecord "/api/request" req []
                  let! resp= res.text()
                  return resp |> decode }

    let requestToResponseCommand respMsg reqMsg =
        reqMsg
        |> post
        |> (fun task ->
        Cmd.ofPromise (fun () -> task) () (Ok >> respMsg)
            (Result.Error >> respMsg))

Well, actually it is the postRecord method which performs the serialization, but this in turn uses Thoth.Json as well, I think. To be sure, the req is a discriminated union type that wraps an object in various 'request layers, i.e. discriminated union types' as shown in my example above.

@halcwb
Copy link
Author

halcwb commented Mar 1, 2019

As a related issue, I discovered that the powerpack lib is no longer in use. The postRecord depends both on Fable.Fetch and Fable.Promise. So, this function is deprecated as well. It is rather trivial to create the function yourself. But when people upgrade to the seperate Fable.Fetch and Fable.Promise, this could be a bit of a surprise.

@MangelMaxime
Copy link
Owner

To be sure, the req is a discriminated union type that wraps an object in various 'request layers, i.e. discriminated union types' as shown in my example above.

Having a reproduction types would helps, so is your type of the form:

type Data =
    { Value : int }

type NestedUnion =
    | Data of Data

type Repro =
    | CaseA of NestedUnion

As a related issue, I discovered that the powerpack lib is no longer in use. The postRecord depends both on Fable.Fetch and Fable.Promise. So, this function is deprecated as well. It is rather trivial to create the function yourself. But when people upgrade to the seperate Fable.Fetch and Fable.Promise, this could be a bit of a surprise.

Yes, we decided to split the Fable.PowerPack package and some people complained because it was using Thoth.Json internally. So Thoth.Json was included in their project even if they wanted to use another JSON library.

A solution could be to create a Thoth.Fetch package or something like that which port this code.

It could be accessible from Thoth.Fetch.putRecord .

@halcwb
Copy link
Author

halcwb commented Mar 1, 2019

The exact type in question which causes the problem is:

module Types =
    module Configuration =
        type Configuration = Setting list

        and Setting =
            { Department : string
              MinAge : int
              MaxAge : int
              MinWeight : float
              MaxWeight : float }

    module Patient =
        module Age =
            type Age =
                { Years : int
                  Months : int
                  Weeks : int
                  Days : int }

        type Age = Age.Age

        /// Patient model for calculations
        type Patient =
            { Age : Age
              Weight : Weight
              Height : Height }

        /// Weight in kg
        and Weight =
            { Estimated : double
              Measured : double }

        /// Length in cm
        and Height =
            { Estimated : double
              Measured : double }

    module Treatment =
        type MedicationDefs = (string * string * float * float * float * float * string * string) list

    module Request =
        module Configuration =
            type Msg = Get

        module Patient =
            type Patient = Patient.Patient

            type Msg =
                | Init
                | Calculate of Patient

        module AcuteList =
            type Msg = Get

        type Msg =
            | PatientMsg of Patient.Msg
            | ConfigMsg of Configuration.Msg
            | AcuteListMsg of AcuteList.Msg

So, in this case a Patient |> Calculate |> PatientMsg which is a Request.Msg.

https://github.com/halcwb/GenPres2/blob/562f7bd19478433a25b198135088645ec91b3054/src/Shared/SharedTypes.fs

@MangelMaxime
Copy link
Owner

Thank you for the reproduction code :)

It will help work on the issue.

@MangelMaxime
Copy link
Owner

I moved this issue to another repository, and further work will take place there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants