Simple-Schema / Collection 2 causing text typing errors

So I’ve got an issue where my users are reporting that when they are typing a reasonable amount into a text box, they are losing characters, specifically spaces, and it’s really damn annoying. What’s weird is, as soon as I remove the Simple-Schema from the collection, it all works fine again.

So here’s a meteor pad demo’ing the issue:"Space%20Issue"%20Test

Try typing a large(ish) amount of text into the text box, with lots of punctuation and spaces. You will probably find that spaces “disappear” when you type (they shouldn’t trim is false).

If you comment out the Schema attach line, you should see it go back to normal, and work fine again. But I have no idea why it’s doing this, or how to fix it.

Not just spaces - I got lots of missing characters.

Agreed, but for some reason, spaces are the most common. @robfallows Have you tried un-attaching the schema as well to check it doesn’t do it without Simple Schema?

Just done that part of the test and I get the same results - random, missing characters. Perhaps not as many as with the attachSchema line in, but still there.

EDIT: Just re-done the test and I withdraw my “Perhaps not as many”. It’s basically unchanged.

Is there some code hanging on a keyup event, which is maybe losing data?

Hmmm that’s weird, I can’t really get any issues at all without Simple Schema attached.

EDIT: Nope, definitely as I said. I created a fork with & one without, the one with screws up, the one without is faultless (other than my cack-handed typing).

EDIT 2: Also created the same project with Meteor Astronomy and I don’t get the same issue… It’s very odd, but I’m sure it’s something to do with Simple Schema or Collection2. Perhaps @aldeed needs to be mentioned…?

I’ve just re-done both tests with the same results again (missing characters in both)!

On the plus side, I’m getting really good at the first few lines of Jabberwocky.

Looking at the code more closely, you are hanging off keyup and changed events. I honestly think that’s your problem - you’re doing a lot of stuff on each keypress.

I changed your events to:{
  'onblur #exampleText': function (event, template) {
    Strings.update({ _id: 'test' }, { $set: { value: event.currentTarget.value } });

and got no errors with or without simple schema.

I would look at debouncing a keyup or changed event to hit the db less often.

Alas, that’s kind of besides the point… I need the reactivity and immediacy of keypress/change updates and that’s what Meteor’s optimistic update strategy is somewhat designed for. (You can’t join’t edit something when you can’t see the other users cursor & typing!)

I still can’t get it to cause any issues what-so-ever without Simple Schema attached.

Take a look at for a workaround.

Thanks @serkandurusoy hadn’t seen that one, and sure enough (while kinda hacky) it’s fixed the issue for me. :thumbsup:

1 Like

Also created the same project with Meteor Astronomy and I don’t get the same issue.

I’m curious, why did you choose not to move on with astronomy? Is there a particular reason?

I’m currently evaluating it (actually kind of begun using it) for a new project and currently have no regrets.

Sorry, perhaps my statement was slightly misleading, I recreated the MeteorPad with Meteor Astronomy and it worked fine.
However, my main project is very near completion, so switching from SimpleSchema & Collection2 to Meteor Astronomy could mean quite a large amount of work, although it’s something I’m still very much tempted to do!

Fair enough, thank you :smile: