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 search page to stop couldnt_find_object error #1669

Merged
merged 5 commits into from Jun 29, 2023

Conversation

scme0
Copy link
Contributor

@scme0 scme0 commented Jun 28, 2023

When searching for anything that isn't a community or user link (starting with a '!' or '@') while logged in, an error appears as a toast on the search page, or if you're loading the search URL directly, it will show an error page.

Toast:
Screenshot 2023-06-28 at 23 29 50

Error page (when loading the search url with the query parameters directly):
Screenshot 2023-06-28 at 23 30 04

This is because we send a request to the server on the resolve_object endpoint which returns an error couldnt_find_object if the input is just random text and it doesn't match to any objects.

I've updated the front end to make the requests to resolve_object silent. This means that if there is any error, no toast is shown and it is not logged. I think this is acceptable because of the way we are using the endpoint here. we are just interested if it returns any valid results.

I'm unsure if there is a better way to implement a "silent client" though, so please let me know if you can think of something a bit more elegant.

Fixes LemmyNet/lemmy#3296

@scme0 scme0 changed the title Fix search page Fix search page to stop couldnt_find_object error Jun 28, 2023
}

export class HttpService {
static #_instance: HttpService;
#silent_client: WrappedLemmyHttp;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a nicer way to achieve this?

Copy link
Member

Choose a reason for hiding this comment

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

I can't think of any.

if (
!(this.state.isIsomorphic || this.props.history.location.state?.searched)
) {
if (!this.state.isIsomorphic) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this because it was causing no search results to display.

@scme0 scme0 marked this pull request as ready for review June 28, 2023 14:02

// If we return this object with a state of failed, the catch-all-handler will redirect
// to an error page, so we ignore it by covering up the error with the empty state.
if (resolveObjectResponse.state == "failed") {
Copy link
Member

Choose a reason for hiding this comment

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

Use triple equals instead of double equals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch - will fix 👍

});

await this.search();
this.props.history.push(`/search${getQueryString(queryParams)}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we create a global siteUrl constant at some point, in case someone installs Lemmy in a subdirectory or something?

@dessalines dessalines merged commit a077924 into LemmyNet:main Jun 29, 2023
1 check passed
@scme0 scme0 deleted the scme/add-silent_client branch June 29, 2023 07: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.

[Bug]: 0.18.0 search is returning "couldnt_find_object" error
4 participants