fable-compiler / Fable.Lit

Write Fable Elmish apps with Lit
https://fable.io/Fable.Lit/
MIT License
91 stars 13 forks source link

Upgrading to Fable.Lit 1.4.2 causes issues in Elmish types #72

Open leolorenzoluis opened 1 year ago

leolorenzoluis commented 1 year ago

I am testing with the Fable.LitRouter and LitState but it requires 1.4.2, I get compilation error if I get 1.4.2 but if I downgrade to 1.4.1 then there's no error. This is just showing in Jetbrain's Rider. If I compile with npm run start then there's no error.

Looking at the commit history/release notes there shouldn't be anything that should affect this in 1.4.2.

Screen Shot 2022-09-27 at 5 53 32 PM Screen Shot 2022-09-27 at 5 56 47 PM

Looking at the release notes there shouldn't be any impact on the Elmish/Lit libs.

For reference this is the sample code that I tried and updating new variables to make it minimal


let initialState1() =
    let monitorPageModel, monitorPageMsg = ListMonitorsPage.init()
    let welcomePageModel, welcomePageMsg = WelcomePage.init()

    let model = { CurrentPage = Anonymous AnonymousPage.Welcome; ServerMessage = []; MonitorModel =  monitorPageModel; WelcomePageModel = welcomePageModel }
    model, Cmd.none

let update1 msg model =
    model, Cmd.none

let view1 model dispatch =
    html $"""
    <div>Hello world</div>
    """

Program.mkProgram initialState update view
|> Program.withLit "my-app"
|> Program.withBridgeConfig (Bridge.endpoint socketEndpoint |> Bridge.withMapping ServerMsg)
|> Program.run
Screen Shot 2022-09-27 at 5 57 51 PM

Update:

Looks like something in these two packages are causing the compiler to get confused.

<PackageReference Include="Fable.LitRouter" Version="1.0.0-beta-005" />
<PackageReference Include="Fable.LitStore" Version="1.0.0-beta-001" />

If I remove that and just keep Lit to 1.4.2 it has no compile error

I've narrowed it down. It's the Fable.LitRouter that's causing an issue. Not sure where the source code for LitRouter is?

I extracted the library and I don't get any errors, so not sure why this is happening?

I removed the Fable.LitRouter and just created a separate fs file from https://nuget.info/packages/Fable.LitRouter/1.0.0-beta-005 Maybe @JordanMarr knows?

alfonsogarciacaro commented 1 year ago

Hmm, not sure what's the problem here but unfortunately we've seen similar issues in the past. This sometimes happens because of type inference in F#, we may do an "innocent" change to a function without type annotations and this may subtly break the signature without us noticing. Because Fable compiles from sources, the type inference in that case works, but in the IDE on when using dotnet build the problem may surface.

I'll try to investigate but in the meantime your solution of adding the source of Fable.LitRouter directly to your project should work. Hopefully publishing a new version of Fable.LitRouter that depends on Fable.Lit 1.4.2 should work too. Sorry for the hassle!