Skip to content
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

defn- should not be exported #455

Closed
ghost opened this issue Feb 1, 2024 · 4 comments
Closed

defn- should not be exported #455

ghost opened this issue Feb 1, 2024 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 1, 2024

Is your feature request related to a problem? Please describe.

React HMR does not work as reliably when a file exports non-react components. The problem is that Clojure by default exports any non private var, and Squint in particular seems to export any variable (this may be a bug).

Example warning from Vite:

12:03:27 AM [vite] hmr invalidate /src/main.jsx Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#consistent-components-exports

Describe the solution you'd like

Only export vars with metadata :export. This would be similar to what shadow-cljs provides for external modules.

@borkdude
Copy link
Member

borkdude commented Feb 1, 2024

Thanks for the issue. By design squint exports any non-private var, that is intentional.
But you're right that squint also exports private vars, created with defn-. This is something we can fix. Would that be a solution to your problem?

@ghost
Copy link
Author

ghost commented Feb 2, 2024

The only drawback is doing def ^:private for any variable.

But perhaps one should be setting up HMR with Clojurescript macros rather than Vite's default React support.

@borkdude
Copy link
Member

borkdude commented Feb 2, 2024

I can't change the current behavior because the normal behavior of ClojureScript is that you can access vars from other ClojureScript namespaces without adding ^:export.

But fixing defn- would be good in all cases, so let's start with that.

I'm not sure what you mean by HMR with CLJS macros.

@borkdude borkdude changed the title allow more control over exports to accommodate React HMR support defn- should not be exported Feb 2, 2024
borkdude added a commit that referenced this issue Feb 2, 2024
@borkdude
Copy link
Member

borkdude commented Feb 2, 2024

Released in 0.6.89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant