-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
Add explanations regarding form submissions and the data-turbo
attribute for Flash Messages
#2486
Open
DocFX
wants to merge
2
commits into
symfony:2.x
Choose a base branch
from
DocFX:patch-2
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+20
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
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.
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.
I'm a bit hesitant here... Turbo is not supposed to prefetch forms, only links right ?
Could you clarify to me in what scenario flash messages would be lost?
Like what URL is the user / what does he do / where is he redirected on / where does he end up beeing on ?
And then at what moment Turbo currently interfer with this process ?
If we can isolate this, maybe we can also add some safe guards to avoid it ?
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.
IDK that's what it did out of the box to me.
When you hover a submit / button, it tries to submit the form to see what's behind it, you can see it in your browser network log. So that empties the flashmessages as they're parsed on destination in a Twig template.
The fix is exactly extracted from the documentation here: https://turbo.hotwired.dev/reference/attributes and worked like a charm.
Let me paste an example.
Here's the action:
Here's its template:
The base template with messages bag extraction:
If you remove the
data-turbo="false"
attribute/value, upon hovering the button, there's an async query that's sent, and browser cache does not seem to be used afterwards, so I got no flashmessage. Adding that attribute, as documented, fixed the problem.(note that I still left the weird code:
and app.request.xmlHttpRequest is same as(false) and app.request.headers.get('x-turbo-request-id') is empty
in the Twig condition, which should be useless now I found the fix, but doesn't hurt.)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.
Well.. let's separate two things here: Turbo prefetch on hover and ... the rest :)
Turbo Prefetch
afaik, the prefetch is a mecanism Turbo uses only for internal links, and for buttons in form that uses GET method -- forms that should not have effects according to the HTTP spec.
And this behaviour can be disabled easily with
data-turbo-prefetch="false"
.See https://turbo.hotwired.dev/reference/attributes#data-attributes
... the rest
That said, i confirm I reproduce the behaviour with a form redirection, but this has nothing to do with hovering something (it does the same thing even when you do not hover), it's related to the way Turbo navigates / handle HTTP responses.
THat's why your suggestion makes me hesistant:
Do you think there is any other method to use flash messages when Turbo is enabled ?
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.
I have yet to find such a solution (apart from adding a query string, but then any further refresh on the target page would retrigger the message).
Let's just delay that PR until someone finds a better idea. :)