squint 2024-11-04

How do you persist state between hot reloads with vite? defonce doesn't seem to work.

👍 1

yes. you need the latest version so make sure to upgrade

It seems vite is doing a page reload:

09:12:23 [vite] hmr invalidate /js/my_component.jsx Could not Fast Refresh ("MyComponent" export is incompatible). Learn more at 
09:12:23 [vite] page reload js/my_component.jsx

so that's the culprit

I think the REPL output isn't compatible with how the vite react plugin works. If I massage the output slightly like:

export var MyComponent
then it works again. Feel free to post an issue about this and I can take a look later this week

Ah, alright thanks. I've copied the above into an issue.

👍 1

published a new version

it works now in the vite-react project

note that any def that isn't a component will trigger a page reload, unless you make it private

👍 1

As long as you don't have a page reload, defonce should work alright

I should add one more qualification: defonce works in REPL mode

so in that case you should use :repl true in the compiler options (on the command line: --repl true )

hmm.. doesn't seem to work with vite though. Eg. if I start with this project https://github.com/squint-cljs/squint/tree/main/examples/vite-react , do I change the bb task to dev:squint (shell "npx squint watch --repl true") ?

Hey @borkdude, thanks for this wonderful library. Nowadays, under Typescript tyranny, squint might be our only savior! 🙂 One question, do you have a priority of squint over cherry or vice versa? May I suggest (sorry, I ignore most of your hard work and I don't know if this is possible) bringing the two under one umbrella? Something like, making cherry just a param flag under squint, eg npx squint -clj or npx squint -cherry. Having only one will gain more attention IMHO. And I also noticed that squint cli has few more options than cherry. Thanks.

@roboli I might do that at one point, but it's complicated

i was also thinking about this before, cherry = squint + persistent data structures