-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fast Refresh #157
Comments
IHMO if possible we should add support for it in Elmish.HMR because that's the current library responsible for handling HMR. Feliz doesn't know about the application state when used with Elmish. It's also important to note that Elmish.HMR will allow us to support any Elmish application like pure Fable.React, pure Feliz, a mix of both or even just pure Elmish with any renderer. |
Yeah that sounds fine to me, I wasn't sure if |
Oops it's No, it's not coupled to React, For example:
|
@MangelMaxime AFAIK |
@Zaid-Ajaj From HMR point of view, that's totally normal. I already have an issue tracking the situation. elmish/hmr#26 What you are describing is something well know in JavaScript and it's also one of the main problems of HMR. If you want to have HMR in your project you need to make your code understand it. This is not something that works out of the box. In Elmish, most of the time you don't see it because the state is in a single place and Elmish.HMR learned to Elmish how to handle it. It's done by shadowing the functions. In the case, of stateful component, you need to write the component in a way it can understand HMR. In order, to have it freely the best would be to implement it directly in the library providing the stateful component otherwise people will have to make sure to open the modules in the right order. For example, if I shadow open Fable.React
open Elmish.HMR in order to have HMR supported. But if the support for HMR is done directly in In general, you should not have impact on the bundle size because you can isolate the HMR code between |
I find something which maybe useful. After run [<ReactComponent>]
let Counter () =
let (count, setCount) = React.useState(0)
Html.div [
prop.style [ style.padding 20 ]
prop.children [
Html.h1 count
Html.button [
prop.text "Increment"
prop.onClick (fun _ -> setCount(count + 2))
]
]
] It will generate js like below. Under folder import { Feliz_React__React_useState_Static_1505 } from "./www/fablejs/.fable/Feliz.1.16.2/React.fs.js";
import { reactApi, reactElement, mkAttr, mkStyle } from "./www/fablejs/.fable/Feliz.1.16.2/Interop.fs.js";
import { ofArray, singleton } from "./.fable/fable-library.3.0.0-nagareyama-rc-007/List.js";
import { createObj } from "./.fable/fable-library.3.0.0-nagareyama-rc-007/Util.js";
import { createElement } from 'react';
export function Counter() {
let properties, elems, xs;
const patternInput = Feliz_React__React_useState_Static_1505(0);
const setCount = patternInput[1];
const count = patternInput[0] | 0;
const xs_1 = ofArray([(properties = singleton(mkStyle("padding", 20)), mkAttr("style", createObj(properties))), (elems = [createElement("h1", createObj(singleton(["children", new Int32Array([count])]))), (xs = ofArray([mkAttr("children", "Increment"), mkAttr("onClick", (_arg1) => {
setCount(count + 10);
})]), createElement("button", createObj(xs)))], mkAttr("children", reactApi.Children.toArray(Array.from(elems))))]);
return createElement("div", createObj(xs_1));
} Hope we can make |
Hi there @albertwoo, Can you please update Feliz to v1.17.0 and see if it works for you? Because fast-refresh is working as of that version and the latest set of dependencies of webpack and friends. Please see SAFE.React where you can see how it is working there as is without changing I am also noticing you are using Parcel. What version of Parcel is that? latest 2.0-beta doesn't implement fast-refresh properly, the nightly version works. See this discussion on the parcel repo |
But the SAFE.React is using I tried to upgrade Feliz to 1.17.0. And I was using parcel |
The webpack plugin is using
It is. However,
I was pretty sure it worked with nightly.443 🤔 but I gave up on parcel because of how unstable it is at the moment and instead defaulted to webpack which is working really well |
I am using 0.9.0 for I may try again when parcel 2 production version is released. |
@albertwoo Can you give the following a try and see if it fixes the problem? Inside of [<RequireQualifiedAccess>]
module Interop =
let reactElement (name: string) (props: 'a) : ReactElement = import "createElement" "react" to [<RequireQualifiedAccess>]
module Interop =
let inline reactElement (name: string) (props: 'a) : ReactElement = import "createElement" "react"
And see if that fixes the import and uses |
Edit |
This is correct, Fable compiles the sources of the packages. About my suggested, fix, please ignore it because it doesn't work. I just tested it out 😓 |
I think some .fs files don't have an equivalent .fs.js file because they aren't used. Which makes sense for Fable.React because Feliz only uses an alias of a type definition from there 😄 |
Ok. It is confuse for me because I thought that library author only need to put |
Yes, library authors only put F# source code in there, Fable compiles those to JS module and puts them relative to where the F# source code was placed. |
I think Line 22 in 30544a5
Any way it does not impact too much. |
@albertwoo Since Feliz v1.18 (now v1.19) the output of Feliz uses |
@Zaid-Ajaj just tried, it works perfect 👍👍👍 |
I am working on an experimentation using Feliz and wanted to test Fast Refresh and I wanted to share my experience as I spent my evening on it yesterday. The support for Fast Refresh is done in majority by the bundler tools which have can their own implementations.
This cause problem when using Elmish still for the application because we always expose at least 2 functions
To summarize, if you use Webpack you need to make all your funtion/type private in your file in order to have Fast Refresh support. If you use snowpack, you can do as you please. However, my experience with snownpack experience not so great, I often have the file in the browser out of sync with what is on my disk. And also I don't find it robust enough yet to be used in production because I often end up tweaking the config or stop/restart the snowpack process. To continue my test I will fork the react plugin and remove the "export check" and see how it goes. |
@Zaid-Ajaj are we good to close this issue? |
@Shmew I haven't gotten into it yet but I wanted to explore what @MangelMaxime has been doing. I think his solution might prove better suited for Feliz apps because each value and function are automatically exported. Maybe we should start a new issue from here, but let's not close this yet 🙏 |
Just for your information, in the end I decided to go with standard a I encountered several issues (sorry it is a long time ago so I don't really remember... but it was probably related to HMR) when trying to go full Feliz way using I think the problem, is that Again, my tests are 2 months old and I don't precisely remember what was the problem. Also because I don't write my application using "classical react components" but using "standard" Elmish way I mostly use Feliz for the API. |
Could the issue with react-refresh-webpack-plugin requiring react components to be the only exports in the file be resolved by making the |
Let's close this one and if there are any concrete issues lingering, we discuss them in a new issue |
The React team is currently in the process of implementing a native HMR solution which deprecates things like react-hot-loader called Fast Refresh.
I figured we should add an issue to keep this on the radar.
There are a some benefits to be gained from this:
In current state there are some logistics that need to be figured out:
window
variables.try .. finally
block and some other things to do with Fast Refresh.The text was updated successfully, but these errors were encountered: