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

Components named 'Create' fail confusingly #2212

Closed
pngwn opened this issue Mar 12, 2019 · 4 comments
Closed

Components named 'Create' fail confusingly #2212

pngwn opened this issue Mar 12, 2019 · 4 comments
Labels
Milestone

Comments

@pngwn
Copy link
Member

pngwn commented Mar 12, 2019

I was recieving an error (intermediate value).$$ is undefined and it turns out this is because I named my component 'Create'. I'm guessing this clashes with an internal Create class or function or a javascript keyword (I don't remember it being one)?

This should probably give a descriptive error (I don't know if it could be renamed?). This was incredibly confusing and difficult to work out what was going on. Renaming fixed it.

REPL

@pngwn
Copy link
Member Author

pngwn commented Mar 12, 2019

Components named Destroy and Update also break, although the component itself mounts without an issue in this case. I guess this is a similar issue with name collisions.

@Conduitry
Copy link
Member

Well this is a new and interesting type of naming conflict, present only in dev mode.

The methods in the object returned by a create_fragment function usually have one-letter names for more compact code. In dev mode, each is given a more descriptive name (via e.g. c: function create() { ... }) so that it can still be called the same way but it will look nicer in stack traces. However, this create shadows any higher-up create (which in this case is the component instance). Similar things will happen in each of the fragment methods.

Making this even more confusing, the REPL by default does not actually show you the dev mode code that it's running and which is causing the error.

@Conduitry Conduitry added the bug label Mar 12, 2019
@Conduitry
Copy link
Member

Presumably the most straightforward way to handle this would be to add the names of each of those methods to the component.usedNames set ahead of time when compiling in dev mode, but we'd need to remember to update that if we ever add another fragment method.

@Conduitry
Copy link
Member

Opened #2213, which instead pushes the deconflicting responsibility into each block/fragment, where it probably belongs. This does mean that the component instance will win out and get the create name, while the create method will get the name create_1.

Rich-Harris added a commit that referenced this issue Mar 15, 2019
deconflict fragment method aliases with other identifiers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants