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(infinite/hits): stop saving the transformed results in cache #4907

Merged
merged 2 commits into from
Sep 14, 2021

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Sep 14, 2021

Summary

Since we introduced getWidgetRenderState, transformItems gets called two times. On its own this isn't problematic, however if the transformItems "mutates" a key, it will receive next the "mutated" hits instead of the ones that come from the results

One thing which is debatable about this PR is which parts should be saved to results.hits. I opted for just the escaped hits, but i wonder if there's any use cases for considering the query id and position as part of the hits directly.

However, I feel like if we want this behaviour, it shouldn't be hits and infiniteHits mutating results, but rather something global that gets called right after the results get returned. In fact, I also think it makes more sense to escape hits there than in hits.

I don't think removing the escapeHTML option is possible here without breaking change though, so if we want to do that, we should mark it as a possibility for a major in this PR

Result

  • transformItems only gets hits that come directly computed from a result, not from a previous transformItems
  • the result of transformItems does not get stored on result.hits (could be considered a breaking change, but I don't think so)

FX-11
fixes #4819

Since we introduced getWidgetRenderState, transformItems gets called two times. On its own this isn't problematic, however if the transformItems "mutates" a key, it will receive next the "mutated" hits instead of the ones that come from the results

One thing which is debatable about this PR is which parts should be saved to `results.hits`. I opted for just the escaped hits, but i wonder if there's any use cases for considering the query id and position as part of the hits directly.

However, I feel like if we want this behaviour, it shouldn't be hits and infiniteHits mutating results, but rather something global that gets called right after the results get returned. In fact, I also think it makes more sense to escape hits there than in hits.

I don't think removing the escapeHTML option is possible here without breaking change though, so if we want to do that, we should mark it as a possibility for a major in this PR

FX-11
fixes #4819
@Haroenv Haroenv requested review from tkrugg, a team and francoischalifour and removed request for a team September 14, 2021 10:04
@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 14, 2021

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 695e11d:

Sandbox Source
InstantSearch.js Configuration
vigorous-panka-ykezn Issue #4819

Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

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

We also mutate the hits in connectAnswers. We should opt for the same strategy everywhere.

@Haroenv
Copy link
Contributor Author

Haroenv commented Sep 14, 2021

Ah yes, I forgot about answers, it's a little different but can also be changed. Note that in answers it's not the global result that's mutated though @francoischalifour

@Haroenv Haroenv merged commit 82dc0ae into master Sep 14, 2021
@Haroenv Haroenv deleted the fix/hits-transform-items branch September 14, 2021 14: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.

Hits widget transformItems is called twice, receives already-transformed items
2 participants