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

Messages for the next page appear on the current one because of prefetching #7713

Closed
2 tasks done
WofWca opened this issue May 29, 2022 · 4 comments
Closed
2 tasks done
Assignees
Milestone

Comments

@WofWca
Copy link
Contributor

WofWca commented May 29, 2022

Describe the issue

In #7565 we added next page prefetching, and it appears to affect the current page in a weird way. See reproduction.

I already tried

  • I've read and searched the documentation.
  • I've searched for similar issues in this repository.

Steps to reproduce the behavior

  1. Use a Chromium-based browser for easier reproduction.
  2. Go to /translate, to the last page of the search (e.g. https://hosted.weblate.org/translate/weblate/application/en/?&offset=2724)
  3. Click "Previous page", or refresh the page.
  4. A "The translation has come to an end." message will appear.

Instead of step 3 you can even open any hosted Weblate page in a new tab, it will show the message, lol.

Expected behavior

Messages only appear for the pages they're supposed to be displayed on.

Screenshots

image

Exception traceback

No response

How do you run Weblate?

weblate.org service

Weblate versions

No response

Weblate deploy checks

No response

Additional context

<link rel="next prefetch" href="{{ next_unit_url }}" />

if not 0 < offset <= num_results:
messages.info(request, _("The translation has come to an end."))

@WofWca
Copy link
Contributor Author

WofWca commented May 30, 2022

Looks like it's from a package.

def info(request, message, extra_tags=""):
"""Add a message with the ``INFO`` level."""
if request is not None:
add_message(get_request(request), constants.INFO, message, extra_tags)

from django.contrib.messages import add_message, constants

I thought we could maybe bail inside the info function if the request has the prefetch header.

@nijel nijel self-assigned this May 30, 2022
@nijel nijel added this to the 4.13 milestone May 30, 2022
@nijel nijel closed this as completed in 8dc6e31 May 30, 2022
@nijel
Copy link
Member

nijel commented May 30, 2022

That would just silently discard the message...

But the message itself is not the problem, this also deletes cached search results from the session, so the search won't be reproducible anymore, what could break translating the last string (if the search would now return less results).

messages.info(request, _("The translation has come to an end."))
# Delete search
del request.session[search_result["key"]]
return redirect(obj)

I think disabling prefetching is the safest way to go for now, I will revert 4222059.

@github-actions
Copy link

The issue you have reported is now resolved. If you don’t feel it’s right, please follow its labels to get a clue for further steps.

  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

@WofWca
Copy link
Contributor Author

WofWca commented May 30, 2022

That would just silently discard the message...

Oh.... Right... Forgot that the prefetched page actually needs to be used. 😅

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

No branches or pull requests

2 participants