dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
600 stars 50 forks source link

RPC / JSON Serialisation issue in latest WS alpha #360

Open mands opened 9 years ago

mands commented 9 years ago

I've been building a site using UI.Next on the client only along with client-server RPC. Over the past few weeks I've been updating it to the latest WebSharper 3 alpha and it's been quite painless.

Unfortunately the update from 3.0.26-alpha to 3.0.36-alpha seems to have broken RPC for a single type. All other types can be serialised fine, however this type returns null and crashes on the client-side with undefined for any member accesses. The type is a simple record representing something similar to a blog post that is instantiated with another concrete record before passing to the client side.

    type T<'a> = {
        id : Guid
        whenCreated : DateTime
        whenModified : DateTime
        authorId : Guid option
        authorName : string option
        cards : 'a list
        title : string
        caption : string option
        postState : PostState
        tags : Tag list
        viewsLeft : int option
        timeLimit : DateTime option
        password : string option
        postAnon : bool
        rankCards : bool
        upVotes : int
        downVotes : int
        flaggedCount : int
    } 

I noticed once during WebSharper compilation that several warnings were shown simlar to 'JSON Schema error from System.String[]' which may be related but I cannot reproduce that. For now I've reverted to 3.0.26-alpha but any help would be appreciated.

Thanks.

Tarmil commented 9 years ago

I just tried to reproduce with 'a = int and without the postState and tags fields, and it worked correctly. What do you instantiate 'a as, and what do the types PostState and Tag look like? The problem is probably in one of those.

mands commented 9 years ago

Thanks for looking. So PostState and Tag are simple discrimiated unions as below,

    type PostState = Processing | Ready | Disabled | Flagged | Deleted

    type Tag = 
        | Tag of string
        | Author of string
        | Group of string

'a is a more complex nested type that is itself parametersied depending on whether it is running on the client or server. I've put together a small test case and will narrow down the fields in 'a in order to narrow down the type that is causing the problem and get back to you. Thanks.

Tarmil commented 9 years ago

Can you still reproduce this issue with 3.0.46-rc1?