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

Search in panel shows old results when response times from server vary #6409

Open
toebu opened this issue Apr 26, 2024 · 1 comment · May be fixed by #6420
Open

Search in panel shows old results when response times from server vary #6409

toebu opened this issue Apr 26, 2024 · 1 comment · May be fixed by #6420
Assignees
Labels
type: bug 🐛 Is a bug; fixes a bug

Comments

@toebu
Copy link

toebu commented Apr 26, 2024

Description

The search in the panel can show partial/old results when the response time from the server can vary. Example: You want to search for "test". You type slowly, so a first query is launched for "te", then another one when you finished typing "test". If the request for "test" is faster to load, it shows those results. If afterwards the request for "te" completes, it overwrites the results shown. So you seem to see the results for "test" but you actually see the results for "te".

Expected behavior
When a new search query is launched, the old running queries should be canceled so that this behaviour can't happen.

To reproduce

Easiest way might be to overwrite the search method to include a random delay:

Kirby::plugin('searchtest', [
    // This is overwriting the search used in the panel
    'areas' => [
        'site' => function ($kirby) {
            return [
                'searches' => [
                    'pages' => [
                        'query' => function (string $query = null, int $limit, int $page) use ($kirby) {
                            sleep(rand(0, 3));
                            // Simply pass on to the core search
                            return $kirby->core()->area('site')['searches']['pages']['query']($query, $limit, $page);
                        }
                    ]
                ]
            ];
        },
    ]
]);

Then go to the panel and quickly type part of the query, wait half a second, then type the rest. You might have to try a few times so that the first query actually takes longer than the second one.

Your setup

Kirby Version
4.2.0

Additional context
The behaviour might not happen with just the default setup and few results. But if you overwrite the panel search with a custom search that e.g. fetches data from a big DB or another API, this happens and there's no way to fix it within the custom search.

@nilshoerrmann
Copy link
Contributor

Just for reference, this issue can be fixed by using abort controllers in the search Vue component: https://developer.mozilla.org/en-US/docs/Web/API/AbortController.

@distantnative distantnative self-assigned this Apr 28, 2024
@distantnative distantnative added the type: bug 🐛 Is a bug; fixes a bug label Apr 28, 2024
@distantnative distantnative linked a pull request Apr 28, 2024 that will close this issue
1 task
@distantnative distantnative linked a pull request Apr 28, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Is a bug; fixes a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants