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

Fix "Unsubscribe" button on accounts page in Firefox. #32

Closed
wants to merge 1 commit into from

Conversation

zarvox
Copy link
Collaborator

@zarvox zarvox commented Aug 16, 2016

Or a less-sensational title that explains the rest of the changeset: avoid
using the global "event" and avoid using "event" as a variable name.

Some browser environments define a global "event" which is set to the current
event that is being dispatched for the duration of event dispatch. Other
browsers do not.

As a result, since a variable named "event" may or may not shadow the global
event object, it's best to avoid the whole confusion and never name a variable
"event" or use a reference named "event". [1]

[1] - http://eslint.org/docs/rules/no-restricted-globals

Or a less-sensational title that explains the rest of the changeset: avoid
using the global "event" and avoid using "event" as a variable name.

Some browser environments define a global "event" which is set to the current
event that is being dispatched for the duration of event dispatch.  Other
browsers do not.

As a result, since a variable named "event" may or may not shadow the global
event object, it's best to avoid the whole confusion and never name a variable
"event" or use a reference named "event". [1]

[1] - http://eslint.org/docs/rules/no-restricted-globals
template._showPrompt.set(true);
},

"click .unsubscribe": function () {
event.preventDefault();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, this access of the global is what broke under Firefox.

@kentonv
Copy link
Member

kentonv commented Aug 19, 2016

I actually think that avoiding naming the parameter "event" makes it more likely that someone will accidentally depend on the global by incorrectly typing "event" on one particular line but magically getting the same object as is bound to "ev" -- except on Firefox.

@zarvox
Copy link
Collaborator Author

zarvox commented Aug 19, 2016

Personally, I disagree. If we have a general "don't use event policy", that's easier to call out in a code review, and not using event anywhere also means that if any of us lazily copy-paste an existing block, the failure mode will be "never-works" rather than "half-works".

As a bonus, your editor's syntax highlighter should highlight event as a global like window or document, so I find it less likely to be problematic. It's easier to detect badness in text when the mistake is wrong text in the code rather than completely absent text (no arg provided), as was the problem here.

Some day we'll have ESLint (once we clean up the codebase enough to not generate thousands of warnings) and can have a rule which disallows accessing the global, in which case the rule will be able to catch bad accesses either way, but until then, I think the fact that this bug existed speaks to the wisdom of shadowing variables like this.

@kentonv kentonv closed this in 8718e38 Aug 19, 2016
@kentonv
Copy link
Member

kentonv commented Aug 19, 2016

Since we closed sandstorm-io/sandstorm#2394 I suppose we should skip the renames here. I pushed a commit that just fixes the bug itself.

@zarvox zarvox deleted the fix-unsubscribe-firefox branch August 29, 2016 18:12
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

Successfully merging this pull request may close these issues.

2 participants