Wrong import path when copy/pasting JSX between components

I have 3 React components, all in separate files with default export

- Component1.js

- Component2.js

- SharedComponent.js

 

If I include SharedComponent in Component1 with auto-completion, the correct import is automatically added :

 

But if I copy/paste ths JSX containing <SharedComponent> into Component2, the wrong import is generated :

Component1.js :

Component2.js :

This bug happen whatever the depth and complexity of the JSX copied, as long as it contained one imported component.

 

This is clearly a bug. At no point any JSX copied from one file should be considered the defautl export from that file. A the very least in this case, no import should be generated.

7 comments
Comment actions Permalink

Looks similar to https://youtrack.jetbrains.com/issue/WEB-36622.

Please check if it's still the issue in WebStorm Early Access Preview build

0
Comment actions Permalink

I'm still experiencing this bug (or some variation of it) in version 2019.1.1.

One specific example for me is lodash imports: import _ from "lodash";

When I copy code from one file to another that includes usages of lodash (_), and the destination file does not yet have an import for lodash, then an incorrect auto import is added to import _ from the source file.

0
Comment actions Permalink

I always have this problem, and combine this with react hooks which throws the error "Rendered more hooks than during the previous" is red herring 

0
Comment actions Permalink

For me this bug has disappeared for a while now... don't know when it was fixed but it's definitely not in 2019.3

1
Comment actions Permalink

@James  Please could you elaborate on this? What IDE version do you use? Can you reproduce the issue in a new project? Note that the Uncaught Invariant Violation: Rendered more hooks than during the previous render is not the issue the IDE can be blamed for, it's a runtime error

0
Comment actions Permalink

Elena Pogorelova I agree it's not entirely IDE's fault, the react error message needs to be improved. But the IDE contributed an important part of the problem by automatically inserted the wrong import path, which caused the run time error to show up. I am still running 2018.3

0

Please sign in to leave a comment.