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

onInput performance ( even crash browser ) #564

Closed
hdriqi opened this issue Sep 15, 2017 · 11 comments
Closed

onInput performance ( even crash browser ) #564

hdriqi opened this issue Sep 15, 2017 · 11 comments

Comments

@hdriqi
Copy link

hdriqi commented Sep 15, 2017

Hi, I am using onInput for my input field. here's the emitter:

emitter.on('inputUsername', (e) => {
		let input = e.target.value
		if(input.length < 9){
			if(input === '' || input.match(/^[a-z0-9]+$/i)){
				state.input.username = input.toLowerCase()
				emitter.emit('render')
			}
			else{
				state.input.username = input.slice(0, input.length - 1)
				emitter.emit('render')
			}
		}
		else{
			emitter.emit('render')
		}
	})

While typing a lot of characters, for example a,b,c,backspace,backspace,d,e, etc will crash the browser ( google chrome in my case ). After a bit of research, the google chrome dump is telling me that the browser ran out of memory.

Also, while testing on my mobile devices the browser doesnt crash but the performance is so bad. After I press a character in the keyboard, the dom need about .3s - .5s to rerender it.

Is there any solution?
I need to make sure the username field less than 9 chars and alphanumeric only.

@bcomnes
Copy link
Collaborator

bcomnes commented Sep 15, 2017

Hard to imagine this event handler would be the cause of of a memory leak. I would suspect the culprits is living in the render cycles.

@hdriqi
Copy link
Author

hdriqi commented Sep 16, 2017

@bcomnes any idea about the workaround?

@graforlock
Copy link
Member

graforlock commented Sep 16, 2017

Are you re-rendering the input fields? I suggest you prevent that for all input fields with .isSame and try again.

Also, you can validate inputs in event handlers checking it like this (these days):

const onInput = e => {
 if(e.target.checkValidity()) {
  ...
 }
}

Using HTML5 validation with regex patterns.

In general, can you reproduce it somewhere on, for example, github repo? That'd be helpful.

@graforlock
Copy link
Member

@hdriqi Are you still experiencing the issue? Is it still a valid issue?

@hdriqi
Copy link
Author

hdriqi commented Sep 22, 2017

@graforlock yes, but i thought that it is because I did the re-render after each user input. So my workaround is that you should not re-render inside the onInput to give validation, instead you need to do it after the users press submit button to avoid the slow performance.

@graforlock
Copy link
Member

graforlock commented Sep 22, 2017

It still shouldn't be technically happening, even though I am not a big fan of re-rendering inputs, this works well in React for instance and I see no reason why wouldn't it.

It has to be looked into. Can you provide reproducible scenario @hdriqi ?

@graforlock
Copy link
Member

I believe this is related to the latest update finds @yoshuawuyts

@yoshuawuyts
Copy link
Member

A repro on this would be good; I can't think of a good reason why this should be happening - even with lots of re-rendering nodes should be able to be garbage collected normally, and only ever cause the program to slow down, not crash.

Also related to this: it's definitely recommended to use html5 validation, as it performs better and is more accessible.

@hdriqi
Copy link
Author

hdriqi commented Oct 11, 2017

@yoshuawuyts just start a new project and using choo. This time oninput does not crash and run smoothly. My previous project that had oninput crash is using JSS (https://github.com/cssinjs/jss) which uses a lot of variables as classname and conditional class (which use function). I think those are the problem that cause the slow down, even crash.

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Oct 11, 2017 via email

@hdriqi hdriqi closed this as completed Oct 11, 2017
@bcomnes
Copy link
Collaborator

bcomnes commented Oct 11, 2017

Perhaps we could figure out if there is something going on between choo and jss.

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

4 participants