-
Notifications
You must be signed in to change notification settings - Fork 431
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
Allow opt-in to breaking out of missing frames #864
Closed
Closed
Conversation
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
This changes the default behaviour when a frame response is missing its expected `<turbo-frame>` element. Previously, when the response was missing its frame, we would trigger a `turbo:frame-missing` event, and then (provided that event wasn't cancelled) perform a full page visit to the requested URL. However there are cases where the full reload makes things worse: - If the frame contents were non-critical, reloading the page can turn a minor bug into a major one. - It can mask some bugs where frames were intend to explicitly navigate out of the frame (`target="_top"`), by incurring a second request that loads the page that makes it seem as if it's working corrects. - It leaves the user at a URL that may never be capable of rendering a valid response (since that URL was only intended to serve a particular frame). That means refreshing the page is no help in getting back to a working state. - It can lose other temporary state on a page, like form values. With this change, we no longer perform the full page visit. Instead, we handle a missing frame by doing two things: - Write a short error message into the frame, so that the problem is visible on the page. - Throw an exception, which should make the problem quite obvious in development, and which allows it to be easily gathered by exception monitoring tools in production. We keep the `turbo:frame-missing` event exactly as before, so applications can still hook in to perform alternative behaviour if they want.
kevinmcconnell
commented
Feb 2, 2023
kevinmcconnell
commented
Feb 2, 2023
kevinmcconnell
force-pushed
the
frames/opt-in-breakout
branch
from
February 2, 2023 16:49
28fb705
to
88bf246
Compare
packagethief
reviewed
Feb 2, 2023
Also remove `invalidate` that has effectively been replaced.
When a frame response is missing its expected `turbo-frame` element, we consider it an error. Normally this is what we want. In certain cases, though, it's better if a response without a matching frame is treated as a full page instead. The classic example of this is a login page being rendered in response to an expired session. To allow this, we provide a way for a page to mark itself as "breakoutable" by including a specific meta tag in its head: <meta name="turbo-frame-missing" content="visit"> When a response is missing its expected frame, but includes that meta tag, we'll perform a full-page visit to it, rather than throw an error.
Rather than use a meta tag in the response, we can put a central list of "breakoutable" paths in a single meta tag, and include that on requesting pages. Assuming that an application will have a small number of these paths, it might be simpler to centralise them in one place and include that in a shared layout.
kevinmcconnell
force-pushed
the
frames/opt-in-breakout
branch
from
February 3, 2023 11:57
88bf246
to
c567587
Compare
kevinmcconnell
force-pushed
the
frames/no-breakout
branch
from
February 6, 2023 11:29
e2542eb
to
00a481e
Compare
We decided to take a different approach to this: #867 lets us solve the problem without introducing new configuration options. |
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.
This builds on #863.
When a frame response is missing its expected
turbo-frame
element, we consider it an error. Normally this is what we want.In certain specific cases, though, it's better if a response without a matching frame is treated as a full page instead. The classic example of this is a login page being rendered in response to an expired session.
To allow specific paths to be opted in to full reloads when they are returned in response to a missing frame, this adds support for an allowlist specified in a meta tag in the document:
When a response is missing its frame, we check if its path matches anything in that list. If so, we perform a full page visit.
This configuration is app-wide, and would typically be included in an application layout.