squint

Ian Chow 2024-11-04T04:46:37.206669Z

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

👍 1
borkdude 2024-11-05T08:09:40.261019Z

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

borkdude 2024-11-05T08:12:50.891139Z

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

borkdude 2024-11-05T08:12:57.495479Z

so that's the culprit

borkdude 2024-11-05T08:16:37.450259Z

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

Ian Chow 2024-11-05T09:43:12.062099Z

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

👍 1
borkdude 2024-11-05T17:19:06.219519Z

published a new version

borkdude 2024-11-05T17:19:36.993219Z

it works now in the vite-react project

borkdude 2024-11-05T17:19:55.191549Z

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

👍 1
borkdude 2024-11-04T09:44:14.125099Z

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

borkdude 2024-11-04T12:56:55.247419Z

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

borkdude 2024-11-04T12:57:11.618979Z

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

Ian Chow 2024-11-05T03:28:45.892279Z

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") ?

roboli 2024-11-04T16:16:43.337929Z

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.

borkdude 2024-11-04T16:30:51.864149Z

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

martinklepsch 2024-11-04T19:34:41.126869Z

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