You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In his scenario there are several events registered and the number in brackets is forth-running. The events trigger as usual and being a good developer he also has an off method:
$(window).on(".myNameSpace[1234]");
Everything looks good, except...
After the code has been running for at while he discovered a memory leak! But why? The off function works, right? Nope (๑•́ ヮ •̀๑)
Turns out the namespace is at some point (source) turned into a regex and tested against existing events... In the case above it means that the brackets are preventing the existing events to be found and are therefore leaked for the runtime of the app.
Suggestions
First of all YES the documentation says to not use special characters, but you know that some developers does not always read the fine prints (◔_◔)
Option 1: Perhaps the on method could throw an exception if any illegal characters are entered? Option 2: Regex-escape the namespace.
Note: I'm of cause not the developer that did not read the documentation...
The text was updated successfully, but these errors were encountered:
This was discussed in the team meeting. Since we clearly document the characters that can be in a namespace, we will leave it as-is. There is a possibility that we might use special characters for other purposes in the future, which is why the limits are there in the first place. If we regex-escape the name it allows things to work for now but removes the ability to define new syntax that uses them without randomly breaking someone's code.
Problem
Events can have namespaces; and as according to the documentation:
If a developer does not see this particular piece of information he could create an event like this:
In his scenario there are several events registered and the number in brackets is forth-running. The events trigger as usual and being a good developer he also has an
off
method:Everything looks good, except...
After the code has been running for at while he discovered a memory leak! But why? The
off
function works, right? Nope (๑•́ ヮ •̀๑)Turns out the namespace is at some point (source) turned into a regex and tested against existing events... In the case above it means that the brackets are preventing the existing events to be found and are therefore leaked for the runtime of the app.
Suggestions
First of all YES the documentation says to not use special characters, but you know that some developers does not always read the fine prints (◔_◔)
Option 1: Perhaps the
on
method could throw an exception if any illegal characters are entered?Option 2: Regex-escape the namespace.
Note: I'm of cause not the developer that did not read the documentation...
The text was updated successfully, but these errors were encountered: