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

Support User: User data defaults to false instead of undefined #6854

Merged
merged 2 commits into from
Jul 18, 2016

Conversation

jordwest
Copy link
Contributor

@jordwest jordwest commented Jul 17, 2016

This is a fix for support user, currently broken.

This change sets the user data to false when the session is a support user session, rather than leaving it as undefined which caused an error in the community translator jumpstart.

This change also adds a condition to exit the community translator jumpstart if no user is found, preventing the exception which could halt the boot process.

Support user starts Calypso with no user, which currently causes the communityTranslatorJumpstart function to fail with an exception Cannot read property 'localeSlug' of undefined - see #3843.

Any code that used this function (usually indirectly via translate) was breaking on the exception.

PR #6645 introduced a notices middleware which indirectly called the translator jumpstart somewhere in the Calypso boot process, before the support user was loaded. The localeSlug error thus broke the Calypso boot process.

Closes #3843

Test live: https://calypso.live/?branch=fix/support-user/localeslug-error

cc @deBhal @rralian @yoavf @dllh

This change adds a condition to exit the community translator jumpstart
if no user is found, preventing an exception which can halt the boot
process.

Support user starts Calypso with no user, which currently causes
the communityTranslatorJumpstart function to fail with an exception
"Cannot read property 'localeSlug' of undefined" - see #3843.

Any process that used this function was breaking on the exception.

Issue #6645 introduced a notices middleware which indirectly called
the translator jumpstart in the Calypso boot process, before the support
user was loaded. The localeSlug error thus broke the Calypso boot
process.

Closes #3843
@jordwest jordwest added [Type] Bug [Pri] High [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. i18n labels Jul 17, 2016
@deBhal
Copy link
Contributor

deBhal commented Jul 18, 2016

The change looks harmless and has a nice defensive flavour, and I'm quite happy for this to go in, but it's a weird error.

currentUser should be false until we've got a valid user. It gets set in User.initialize() here https://github.com/Automattic/wp-calypso/blob/4105161c2978c28aaac7bfe77658481ae21a7cf7/client/lib/user/user.js or on line 75 just below it.

false.localeSlug evaluates to undefined, which is also falsey, so || ! false.localeSlug should cause this to bail out until the user is loaded (wat).

The only way to get Cannot read property 'localeSlug' of undefined is if User.data is being set to undefined, which it shouldn't be - fetch() might set it to an empty object, and clear() will set it to an empty array oddly enough, but it shouldn't ever be undefined. I'd check that the support user code isn't doing something odd here.

@deBhal deBhal added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jul 18, 2016
@jordwest
Copy link
Contributor Author

Ahh! Good catch @deBhal. While other paths were setting the user data to false, support user was exiting early and leaving the user data undefined. Fixed in e19d213.

The change in translator-jumpstart is no longer necessary - do you think it's worth keeping anyway?

@deBhal
Copy link
Contributor

deBhal commented Jul 18, 2016

I think leave it in. It won't make any logical difference, but it reads a bit more naturally.

🚢

@jordwest jordwest changed the title Community Translator: Don't run when no user found Support User: User data defaults to false instead of undefined Jul 18, 2016
@jordwest jordwest merged commit c80dc40 into master Jul 18, 2016
@jordwest jordwest deleted the fix/support-user/localeslug-error branch July 18, 2016 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support User: localeSlug error when active
3 participants