Skip to content

fix(autocomplete-js): update components with new renderer#946

Merged
sarahdayan merged 12 commits intonextfrom
fix/components-renderer
Apr 12, 2022
Merged

fix(autocomplete-js): update components with new renderer#946
sarahdayan merged 12 commits intonextfrom
fix/components-renderer

Conversation

@sarahdayan
Copy link
Copy Markdown
Member

@sarahdayan sarahdayan commented Apr 11, 2022

This fixes an issue where default components aren't updated with the new createElement when updating the renderer with the Update API.

The issue was caused by the fact that user-provided components are merged last (which allows users to override default components with their own). The consequence is that when updating the options, the "old" default components are therefore merged and override the new ones.

The difficulty is that, because users can technically override default components (provide Highlight, Snippet, etc.), we can't just update default components by name. Therefore, this PR identifies default component with an internal property so that we can only update them and leave user components untouched.

In a future major, it would be simpler to disallow registering components with the same name as default components. It would require less code and remove confusion without removing any important capabilities.

Since this PR was about components, I also implemented the final unimplemented tests.

fixes #934

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Apr 11, 2022

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 c62ac1e:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-instantsearch Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-preview-panel-in-modal Configuration
@algolia/autocomplete-example-react-renderer Configuration
@algolia/autocomplete-example-starter-algolia Configuration
algolia/autocomplete Configuration
@algolia/autocomplete-example-reshape Configuration
@algolia/autocomplete-example-vue Configuration

@sarahdayan sarahdayan marked this pull request as ready for review April 11, 2022 20:55
Comment thread packages/autocomplete-js/src/__tests__/api.test.ts Outdated
Comment thread packages/autocomplete-js/src/autocomplete.ts Outdated
Comment thread packages/autocomplete-js/src/getDefaultOptions.ts Outdated
Copy link
Copy Markdown
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

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

Nitpicky suggestion

Comment thread packages/autocomplete-js/src/utils/pickBy.ts
@sarahdayan sarahdayan merged commit 8fa038b into next Apr 12, 2022
@sarahdayan sarahdayan deleted the fix/components-renderer branch April 12, 2022 11:10
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.

Update components when renderer is updated

3 participants