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

Prevent auto-instantiation of components with oncreate #103

Closed
Rich-Harris opened this issue Jun 12, 2017 · 4 comments
Closed

Prevent auto-instantiation of components with oncreate #103

Rich-Harris opened this issue Jun 12, 2017 · 4 comments

Comments

@Rich-Harris
Copy link
Member

Because components are currently recompiled and reinstantiated on each keystroke, work that happens in an oncreate handler happens over and over again, which can be a little annoying in some cases (e.g. if you're doing a fetch, and it keeps making requests for non-existent resources because you're in the middle of typing the URL).

One way we could prevent that is by waiting for user input before instantiating components — e.g. expecting a Cmd-Enter or a button click.

The same is true for e.g. media elements.

Easiest thing to do is probably to have an option that lets you choose between as-you-type and on-command instantiation. One step beyond that would be to automatically choose between the two based on whether there's an oncreate or a media element (or any other similar conditions?). That would require that we have access to the component's AST, which would presumably mean updating svelte.compile to return a {code, map, ast} object instead of just code and map.

@Rich-Harris
Copy link
Member Author

Oh, and import declarations

@Ryuno-Ki
Copy link

Have you considered throttling or debouncing it?

@Ryuno-Ki
Copy link

Interesting to learn, that it can be turned into an attack in some implementations: https://blog.0day.rocks/practical-waterholing-through-dns-typosquatting-e252e6a2f99e

@Rich-Harris
Copy link
Member Author

This has been implemented crudely for some time, and less crudely now that we have stats sveltejs/svelte#1299

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

2 participants