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(Configure): prevent aroundRadius="all" throwing #6193

Merged
merged 2 commits into from
May 14, 2024

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented May 13, 2024

Summary

Because React props are not writable, behaviour inside _parseNumbers > merge in the helper requires the configure props to be writable.

fixes #6136

See #6011 for the ultimate cause of this issue; _parseNumbers mutates the arguments as it's much more performant than making a copy on every interaction (this is a very hot function).

Result

This bug is reproducible by simply rendering <Configure aroundRadius="all" /> or any other numeric (

var numberKeys = [
'aroundPrecision',
'aroundRadius',
'getRankingInfo',
'minWordSizefor2Typos',
'minWordSizefor1Typo',
'page',
'maxValuesPerFacet',
'distinct',
'minimumAroundRadius',
'hitsPerPage',
'minProximity',
];
) key as a non-number string. After this PR, the bug no longer happens.

Note that of course this has a performance penalty (or regression) for the Configure widget. There's no way around this as far as I can tell, unless we'd manually make the props writable, but that seems like a bad idea.

Because React props are not writable, behaviour inside _parseNumbers > merge in the helper requires the configure props to be writable.

fixes #6136

This bug is reproducible by simply rendering `<Configure aroundRadius="all" />` or any other numeric (https://github.com/algolia/instantsearch/blob/d1aa720c8e4e1aad2d7b64e385a29b258240c7df/packages/algoliasearch-helper/src/SearchParameters/index.js#L239-L251) key as a non-number string.
@Haroenv Haroenv requested review from a team, dhayab and aymeric-giraudet and removed request for a team May 13, 2024 14:54
Copy link

codesandbox-ci bot commented May 13, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bd84738:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration

This seems to be needed because the location of the babel helpers needs to change to support this new usage of spread.

I don't see any rhyme or reason to why it actually happens or why that has such a large impact for just moved code, but the babel helpers clearly are already very inefficient (many duplicates of the same helper functions) that this probably is fixed if we take a look later to improve this.
@Haroenv Haroenv merged commit cf5a326 into master May 14, 2024
12 checks passed
@Haroenv Haroenv deleted the fix/configure-string-numbers branch May 14, 2024 06:04
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.

Uncaught (in promise) TypeError: Cannot assign to read only property 'aroundRadius' of object '#<Object>'
2 participants