Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) from version [0.1.0] moving forward.

## [0.2.1] - 2025-06-28
### Fixed
- Bug fix targeting issue ([#53](https://github.com/fable-compiler/vite-plugin-fable/issues/53)) as log warn and no crash, for protocol error in json rpc serialization when there is id count mismatch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changelog entry lacks consistency. Please adhere to a uniform format and avoid trends.

Additionally, it appears that not many fixes are being made. This could be misleading for end-users, so I would prefer to follow the updates in your other PR.

- removed Nojaf.React bindings nuget package and using Feliz instead for sample-project, as it is what is most used in community projects and suggested by official fable docs for React.
- pr ([#55](https://github.com/fable-compiler/vite-plugin-fable/pull/55))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added change log entries


## [0.2.0] - 2025-06-24
### Changed
- Upgrade to Vite 7.0.0 as peer dependency and adjust transform hook to use latest filter property, pr ([#49](https://github.com/fable-compiler/vite-plugin-fable/pull/49)), targets issue ([#39]([#39](https://github.com/fable-compiler/vite-plugin-fable/issues/39))
Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,28 @@ export default function fablePlugin(userConfig) {
state.dotnetProcess.stdout,
);

if (process.env.VITE_PLUGIN_FABLE_DEBUG) {
state.endpoint.on("error", (...args) => {
logDebug("protocol", `[fable] error event args: ${args.map(a => typeof a + ': ' + JSON.stringify(a)).join(" | ")}`);
});
}

// Attach protocol-level error handler
state.endpoint.on("error", async (err) => {
if (err && /id mismatch/.test(err)) {
logWarn(
"protocol",
`error from JSONRPCEndpoint: ${
err && err.message ? err.message : err
}`
);
}
else {
logError("unknown", `error: ${err}, ${err.code}, ${err.context ?? "no context"}`);
}
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated handling of error



if (state.isBuild) {
await projectChanged(
this.addWatchFile.bind(this),
Expand Down
6 changes: 3 additions & 3 deletions sample-project/App.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<ItemGroup>
<PackageReference Include="Fable.Browser.Dom" Version="2.14.0" />
<PackageReference Include="Fable.Core" Version="4.3.0" />
<PackageReference Include="Nojaf.Fable.React" Version="0.0.2" />
<PackageReference Include="Feliz" Version="2.9.0" />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update to standard fable Feliz remove Nojaf.Fable.React experimental package from sample

<PackageReference Include="Thoth.Json" Version="10.2.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="Math.fs" />
<Compile Include="Component.fsi" />
<Compile Include="Component.fs" />
<Compile Include="./components/TestComponent.fs" />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added an external component as the issue only happens when there is at least one component importing another it seems, not only with a root component

<Compile Include="RootComponent.fs" />
<Compile Include="Library.fs" />
</ItemGroup>
</Project>
17 changes: 0 additions & 17 deletions sample-project/Component.fs

This file was deleted.

6 changes: 0 additions & 6 deletions sample-project/Component.fsi

This file was deleted.

9 changes: 4 additions & 5 deletions sample-project/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ open Fable.Core
open Browser.Dom
open Math
open Thoth.Json
open Fable.React

let r = sum 1 19

let someJsonString =
Encode.object [ "track", Encode.string "Changes" ] |> Encode.toString 4

let h1Element = document.querySelector "h1"
let h1Element = document.querySelector "#dyn"
h1Element.textContent <- $"Dynamic Fable text %i{r}! %s{someJsonString}"

open React

let app = document.querySelector "#app"
ReactDom.createRoot(app).render (JSX.create Components.Component.Component [])
let root = Feliz.ReactDOM.createRoot(document.getElementById "app")
root.render(Components.RootComponent.El())
19 changes: 19 additions & 0 deletions sample-project/RootComponent.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Components.RootComponent

open Feliz
open Fable.Core

JsInterop.importSideEffects "./app.css"


[<ReactComponent>]
let El () =
let count, setCount = React.useState 0
React.fragment [
Test.El({| name = "Test" |})
Html.h1 "Vite fable plugin rocks!"
Html.button [
prop.onClick (fun _ -> setCount (count + 1))
prop.text $"Current state {count}"
]
]
5 changes: 5 additions & 0 deletions sample-project/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ h1 {
box-shadow: 0px 3px 3px 0px rgba(0,0,0,0.25);
}
}
}

#test {
color: red;
background-color: yellow;
}
27 changes: 27 additions & 0 deletions sample-project/components/TestComponent.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Components.Test

open Feliz
open Fable.Core

// for editor highlight: alfonsogarciacaro.vscode-template-fsharp-highlight
[<Erase>]
let inline css s = s

[<ReactComponent>]
let El (props: {| name: string |}) =
let spinCss = css "@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }"
React.fragment [
Html.div [
prop.style [
style.backgroundColor "yellow"
style.animationName "spin"
style.animationDuration 3
style.animationIterationCount.initial
style.animationTimingFunction.linear
]
prop.children [
Html.h1 $"My name is: {props.name}!"
]
]
Html.style spinCss
]
2 changes: 1 addition & 1 deletion sample-project/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<div id="root">
<h1>Static text</h1>
<h1 id="dyn">Static text</h1>
<div id="app"></div>
</div>
<script type="module">
Expand Down
1 change: 1 addition & 0 deletions sample-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "bunx --bun vite",
"dev:debug": "VITE_PLUGIN_FABLE_DEBUG=1 bunx --bun vite",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added dev debug script

"build": "bunx --bun vite build",
"preview": "bunx --bun vite preview"
},
Expand Down
4 changes: 2 additions & 2 deletions sample-project/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
},
plugins: [
Inspect(),
fable({ jsx: "automatic" }),
react({ include: /\.fs$/ }),
fable(),
react({ include: /\.fs$/, jsxRuntime: "classic" }),
],
});