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

prepareHost is being called with an array; results in t.toLowerCase is not a function error #560

Closed
gajus opened this issue Jun 16, 2017 · 5 comments

Comments

@gajus
Copy link

gajus commented Jun 16, 2017

I am not able to consistently reproduce the issue. However, somehow this part of the code:

function prepareHost(protocol) {
return function prepare(host) {
return protocol + '//' + host.toLowerCase();
};
}

gets called with an array instead of a string.

I have added console.log:

function prepareHost(protocol) {
  return function prepare(host) {
    console.log('host', host);
    return protocol + '//' + host.toLowerCase();
  };
}

I can the first invocation:

host 07QFUIN3KT-dsn.algolia.net

followed by:

host (3) ["07QFUIN3KT-3.algolianet.com", "07QFUIN3KT-2.algolianet.com", "07QFUIN3KT-1.algolianet.com"]

Weirdly, this is happening only in a webpack bundle thats minified using Babili (which makes it near impossible to debug).

@gajus
Copy link
Author

gajus commented Jun 16, 2017

Upon closer inspection, the problem is that here, the value of this.hosts.read and this.hosts.write is:

this.hosts.read (2) ["07QFUIN3KT-dsn.algolia.net", Array(3)]
this.hosts.write (2) ["07QFUIN3KT.algolia.net", Array(3)]

whereas it is clear from the rest of the code that it should be a flat list.

@gajus
Copy link
Author

gajus commented Jun 16, 2017

Turns out it is Babili issue.

Here is the relevant bug report:

babel/minify#583

Basically, it breaks how Array.prototype.concat works here:

this.hosts.read = [this.applicationID + '-dsn.algolia.net'].concat(defaultHosts);
this.hosts.write = [this.applicationID + '.algolia.net'].concat(defaultHosts);

@gajus gajus closed this as completed Jun 16, 2017
@vvo
Copy link
Contributor

vvo commented Jun 16, 2017

Wow thanks for the bug inspection, minifiers are tricky :)

@Haroenv
Copy link
Contributor

Haroenv commented Jun 18, 2017

After reading that Babili issue, it’s not clear to me if that fix is already released, and upgrading helped you or are now not using babel anymore @gajus

@gajus
Copy link
Author

gajus commented Jun 19, 2017

It is not fixed. You need to disable "evaluate" plugin. See:

https://github.com/babel/babili/tree/master/packages/babel-preset-babili#options

If you are using Babili via webpack, you can disable it as such:

new BabiliPlugin({
  // @see https://github.com/algolia/algoliasearch-client-javascript/issues/560
  evaluate: false
}),

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

3 participants