Oh, this may be a tricky one indeed, I will need to check why does WS does not fail on compile with an error message about decimals.

It seems that you are returning some type from RPC that has decimal values inside, for which WS relies on the math.js library to handle on the client side.

You need to add WebSharper.MathJS nuget reference to your project, I think that should resolve this.

By on 7/18/2019 10:07 AM ()

Yes you are right I am doing RPC with decimals inside. I will apply your solution for this tomorrow morning when I am back in the office. Thank you. But there is another part of the problem that I don't understand. Where I have the "try with" I removed all the code an returned the Error "test..." without any RPC call and still I couldn't see the Doc rendered with such a text. So it seems there must be another bug (of mine) also in the view to doc html part. Thanks again for your support and patience!

Edit We'll, I don't know, maybe this is also a side effect of the missing reference, so I guess it's better if I try to add it, first of all. Then we will see if it's all resolved

Edit 2 Actually I've tested the proof of concept - without RPC - on Try WebSharper and it should be ok. I must have messed up things with a missing reference of something like that in my orirginal project...

By on 7/18/2019 10:16 AM ()

Tried again at home. I can't see any issue with the view to doc rendering without calling the rpc server here: so far so good.

But when I add WebSharper.MathJS and the rpc call to the server, I get a different error. What should I do next? Thank you

Uncaught TypeError: Cannot read property 'create' of undefined
    at Object.SC$1.$cctor (WebSharper.MathJS.Extensions.js?h=1053840104:40)
    at Object.Decimal.WSDecimalMath (WebSharper.MathJS.Extensions.js?h=1053840104:33)
    at n (WebSharper.MathJS.Extensions.js?h=1053840104:22)
    at Object.Decimal.CreateDecimal (WebSharper.MathJS.Extensions.js?h=1053840104:29)
    at Object.Decimal.CreateDecimalBits (WebSharper.MathJS.Extensions.js?h=1053840104:15)
    at decode (WebSharper.Main.js?h=-1912156602:270)
    at WebSharper.Main.js?h=-1912156602:324
    at Object.Json.shallowMap (WebSharper.Main.js?h=-1912156602:326)
    at decode (WebSharper.Main.js?h=-1912156602:259)
    at Object.Arrays.map (WebSharper.Main.js?h=-1912156602:2387)

Edit Well, I guess I'll return just strings from the server rpc call ;-)


By on 7/18/2019 1:17 PM ()

Hm, WS should auto-include a script link to https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.13.3/math.js for the math.js lib.

Do you have this link?

Tip: if you want to make WS to download remote resources at compile time and serve them locally, add "downloadResources": true to the wsconfig.json

By on 7/18/2019 2:18 PM ()
By on 7/18/2019 3:11 PM ()

Oh, I have realized, your sample also works if you add [<JavaScript>] on both your Trade and TradeResponse types. Non-JS-annotated types work as plain objects in client-side code but to have type dependency graph for them, they need the annotation. I see that this can be pretty confusing, maybe adding a compiler warning when returning types without full client-side support would help reduce confusion, what do you think?

By on 7/18/2019 3:49 PM ()

Perfect! The support of Websharper is really awesome, thank you very much for the immediate and helpful solution!

By on 7/18/2019 4:04 PM ()

Now I am in the office and I don't understand why I can't make it work when I switch to the project with the real db connection. It seems that the main difference is that at home I have .net 4.7 and here it is .net 4.6. I downloaded the zip, downgraded from 4.7 to 4.6, did a lot of tricks and "massaged" the nuget assembly and I can see that the above demo project is working also in the office environment. But I don't understand what I have to do for the original project, though. Before attaching here a link to another zip, I will try to see if the problem persists even if I delete the sql part... I'm trying not to disturb you with another question, but I've spent a day trying to understand and honestly I am really curious :-) to discover what is the issue here. I will write again with more specific info soon, thank you in advance for your help!

By on 7/19/2019 12:28 AM ()

I don't think .NET versions should matter. So in conclusion, it was a 2-part fix: have the WebSharper.MathJS package, and [<JavaScript>] on the data types used for remoting (to allow to WS auto-discover the dependency) or at least one decimal construction or operation on the client-side. Feel free to post the error message if there is still another one, but I would think that would be an unrelated issue.

By on 7/19/2019 1:23 AM ()

I have a project with all the above fixes AFAICS but it doesn't react to the view... The zip with bin and packages is here I can't spot any problem in source files and config, I see the above said msg only in IE but it doesn't work with Chrome either. It can well be unrelated to the decimal issue, because I'm using no decimal fields here.

By on 7/19/2019 2:30 AM ()

Argh, this happens because metro.js adds some extra functions on Array prototype, and WebSharper's HashSet proxy uses for (... in ...) which now hits the added functions. JS is crazy... I will add a quick fix to solve this while still keeping ES4 compatibility for now.

By on 7/19/2019 3:55 AM ()

You have the mind of a genius, I can hardly follow you: it sounds so complicated. Don't hurry for me, this is a proof of concept, an experiment with WebSharper and Metro UI CSS, so I don't need to deliver this in production today. But thank you for your great assistance

By on 7/19/2019 4:09 AM ()

I have just been using Crome debugger and have seen a lot of JS weirdness although it can still surprise me.

Because this is more an issue in metro.js (it is not a nice move to add enumerable properties on Array prototype), as a fix, you can include this on top of your RetrieveTrades client renderer function (or move to a separate function and call on every page where you would use metro.js)

// make Array functions added by metro.js not enumerable to avoid WS HashSet issue
JS.Inline "Object.defineProperties(Array.prototype, 
        shuffle : { enumerable : false }, 
        clone : { enumerable : false }, 
        unique : { enumerable : false }, 
        from : { enumerable : false }, 
        contains : { enumerable : false }, 
    })" |> ignore

Or add this script in your template after the <script ws-replace="scripts"></script> placeholder tag.

By on 7/19/2019 4:22 AM ()

If it doesn't impact the features of metro style, especially the inspector button that I should be able to click after the table is retrieved and rendered on the page, your solution is ok (and also very instructive) for me. I'll test this likely on Monday. Thank you and have a nice weekend!

By on 7/19/2019 4:48 AM ()

Ehm ... I don't need the DB connection, I can test this at home with the last zip above.

Actually it seems that the header and therefore the Inspector is OK but there are no rows shown in the final table that appears in the Web page.

FYI I'm also trying to open an issue on Metro UI github

Edit Based on the answer of Olton I've closed the issue on Metro-UI-CSS. If I correctly understand, the issue of the extra methods on the Array prototype is solved indeed, as you explained above, without any impacts on the Table component. But I see that there is another incompatibility between metro.js and WebSharper, since the rows of the table disappear. This technical issue is still to be analyzed, though.

Final Edit The last issue of the missing rows was my fault, I missed the tbody

yield tbody [] [
  for tup in trades do
    yield tr [] [
        for (k,v) in tup do
            yield td [] [text <| string v]
    ] ]

WOW Everything is solved!!! Thank you so much!!!

By on 7/19/2019 7:32 AM ()

This really seems like a bug in HashSet proxy... trying to fix, will notify you when new build is available.

By on 7/19/2019 3:13 AM ()

This line in the Main.fs - after the div with the Client function - is triggering the "bug"

Doc.WebControl (new Web.Require<MetroScript>())


By on 7/19/2019 4:02 AM ()

The good news is that if I start from the project built at home and I add all the sql db part there, it does work!

It seems that it is just the initial template for VS that produces a wrong project here at the office, I would say for .net 4.6.1 or I don't know what.

By on 7/19/2019 3:05 AM ()

Don't know if is relevant but I see this in the IE console when I first load the page

WebSharper: Uncaught asynchronous exception Error: Index was outside the bounds of the array.
   "WebSharper: Uncaught asynchronous exception"
      [functions]: ,
      __proto__: { },
      description: "Index was outside the bounds of the array.",
      message: "Index was outside the bounds of the array.",
      name: "Error",
      stack: "Error: Index was outside the bounds of the array.
   at Operators.FailWith (http://localhost:55967/Scripts/WebSharper/WebSharper.Main.js?h=-1912156602:4920:3)
   at Arrays.checkBounds (http://localhost:55967/Scripts/WebSharper/WebSharper.Main.js?h=-1912156602:1917:4)
   at Arrays.set (http://localhost:55967/Scripts/WebSharper/WebSharper.Main.js?h=-1912156602:1931:3)
   at CopyTo (http://localhost:55967/Scripts/WebSharper/WebSharper.Main.js?h=-1912156602:3970:44)
   at HashSet.ToArray (http://localhost:55967/Scripts/WebSharper/WebSharper.UI.js?h=-1969935393:246:3)
   at HashSet.Filter (http://localhost:55967/Scripts/WebSharper/WebSharper.UI.js?h=-1969935393:226:3)
   at NodeSet.Filter (http://localhost:55967/Scripts/WebSharper/WebSharper.UI.js?h=-1969935393:4025:3)
   at relevant (http://localhost:55967/Scripts/WebSharper/WebSharper.UI.js?h=-1969935393:4125:4)
   at Docs$1.ComputeChangeAnim (http://localhost:55967/Scripts/WebSharper/WebSharper.UI.js?h=-1969935393:4127:3)
   at Anonymous function (http://localh"

But I have no error shown in Chrome console (even if it doesn't work there, either), so I'm confused

By on 7/19/2019 1:21 AM ()

Deleted all the sql part, there is only a fake server call. Thank you so much in advance for your reply. I learn a lot from your knowledge

This is the zip of the proj without bin and packages (it should be enough to build it)

By on 7/19/2019 1:46 AM ()

Thanks for the repro, I have created an issue to track, looking into this: https://github.com/dotnet-websharper/core/issues/1058

There is a quick and dirty workaround: include 0m |> ignore anywhere in client-side code, then WebSharper will know to include math.js script link directly :)

By on 7/18/2019 3:40 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper