solidjs / solid

A declarative, efficient, and flexible JavaScript library for building user interfaces.
https://solidjs.com
MIT License
32.22k stars 919 forks source link

`Illegal reassignment of import ...`-bug when setting imported function to ref-prop #2313

Open bigmistqke opened 1 week ago

bigmistqke commented 1 week ago

Describe the bug

// binding.ts
export function binding(element){
}

// this_does_not_work.ts 
import {binding} from "./binding"
import {render} from "solid-js/web"

render(() => <div ref={binding}/>, document.body)

If you run this in development mode it will run without error, but when building it we get the Illegal reassignment of import ...-bug. Something with the transform that it tries to ref={element => binding = element} instead of calling the function.

When you alias the import it will not fail:

// this_does_work.ts 
import {binding} from "./binding"
import {render} from "solid-js/web"

const _binding = (element) => binding(element)

render(() => <div ref={_binding}/>, document.body)

Your Example Website or App

https://github.com/bigmistqke/illegal-solid-bug

Steps to Reproduce the Bug or Issue

  1. run pnpm dev -> runs perfect
  2. run pnpm build -> Illegal reassignment of import "binding" in "src/index.tsx" error

Expected behavior

I expected the binding-function to be called and the transform not try to assign to imports.

Screenshots or Videos

No response

Platform

Additional context

No response

bigmistqke commented 1 week ago

I did not notice the warning in development:

4:38:00 PM [vite] warning: This assignment will throw because "tabIndentation" is an import
168|          _el$35.$$input = e => setValue(e.currentTarget.value);
169|          var _ref$ = tabIndentation;
170|          typeof _ref$ === "function" ? _$use(_ref$, _el$35) : tabIndentation = _el$35; 
   |                                                               ^
171|          _el$35._$owner = _$getOwner();
172|          _$effect(_p$ => {

  Plugin: vite:esbuild
  File: /Users/bigmistqke/Documents/GitHub/tm-textarea/dev/index.tsx

so I guess this is to be expected.