-
Notifications
You must be signed in to change notification settings - Fork 331
fix(redirect): race condition with mismatched query #1310
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 31f1287:
|
Haroenv
reviewed
Apr 24, 2025
packages/autocomplete-plugin-redirect-url/src/types/Redirect.ts
Outdated
Show resolved
Hide resolved
Haroenv
reviewed
Apr 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect, thanks for handling this edge case!
packages/autocomplete-plugin-redirect-url/src/types/Redirect.ts
Outdated
Show resolved
Hide resolved
packages/autocomplete-plugin-redirect-url/src/createRedirectUrlPlugin.ts
Outdated
Show resolved
Hide resolved
Haroenv
approved these changes
Apr 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
There is a race condition caused by requests being resolved without concern for order. For example, here's a local example with the redirect plugin missing the redirect item with the correct query. The first two logged strings in each log are the query stored in the state (which the redirect plugin leverages) and the query from the resolved request. The last log is the response actually used by autocomplete and the plugin though we would expect the second from last one as it has a matched query from the state and response. Side note: the playground in the screenshot was modified to keep the dropdown open, which normally will not happen.
Result
This is a bit of a mixed PR as having to touch more of the redirect plugin has exposed some opportunity for test and typing cleanup.
onResolve
to return early if the query used in the state (i.e. the input query value) does not match the query returned in the resolved responsetransformResponse
function to return an object instead of the redirect url as a stringexpect({}).toHaveTextContent(...)
instead ofexpect({}.textContent).toBe(...)
Testing
This happens especially with Safari, though still not always. See the video recording shared in the CR ticket: https://algolia.atlassian.net/browse/CR-8225
Screen.Recording.2025-04-23.at.2.30.18.PM.mov