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

Bugfix: Redirects and [data-turbo-cache=false] #674

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

seanpdoyle
Copy link
Contributor

When redirecting to a page that contains elements marked with
[data-turbo-cache="false"], those elements are removed before the
initial render, instead of after the render and before the page is
cached.

This behavior seems to have stemmed from hotwired/turbo#516, which
was shipped in response to hotwired/turbo#515.

As an alternative to the willRender: false option passed to
this.adapter.visitProposedToLocation in Visit.followRedirect, the
implementation can instead rely on the presence of the
turbo-frame[complete]
to guard against double fetching.

To guard against regressions, this commit adds coverage for the unwanted
behavior by redirecting from navigation.html to cache_observer.html,
and asserting the presence of a [data-turbo-cache="false"] element
that resembles and application's Flash messaging.

When redirecting to a page that contains elements marked with
`[data-turbo-cache="false"]`, those elements are removed _before_ the
initial render, instead of _after_ the render and _before_ the page is
cached.

This behavior seems to have stemmed from [hotwired#516][], which
was shipped in response to [hotwired#515][].

As an alternative to the `willRender: false` option passed to
`this.adapter.visitProposedToLocation` in `Visit.followRedirect`, the
implementation can instead [rely on the presence of the
`turbo-frame[complete]`][comment] to guard against double fetching.

To guard against regressions, this commit adds coverage for the unwanted
behavior by redirecting from `navigation.html` to `cache_observer.html`,
and asserting the presence of a `[data-turbo-cache="false"]` element
that resembles and application's Flash messaging.

[hotwired#515]: hotwired#515
[hotwired#516]: hotwired#516
[comment]: hotwired#515 (comment)
[hotwired#487]: hotwired#487
@dhh dhh merged commit 256418f into hotwired:main Aug 11, 2022
@seanpdoyle seanpdoyle deleted the data-turbo-cache-bug branch August 11, 2022 13:13
seanpdoyle added a commit to seanpdoyle/turbo that referenced this pull request Nov 25, 2022
Closes [hotwired#794][]

Reverts the implementation change made in [hotwired#674][], and in
its place passes `shouldCacheSnapshot: false` alongside `willRender:
false` for the `action: "replace"` Visit proposed when following a
redirect.

In order to test this behavior, this commit introduces the
`readBodyMutationLogs` test utility function, along with the
`window.bodyMutationLogs` property and the `BodyMutationLog` type.

`BodyMutationLog` instances are pushed onto the log `Array` whenever the
`<body>` element is replaced.

[hotwired#794]: hotwired#794
[hotwired#674]: hotwired#674
seanpdoyle added a commit to seanpdoyle/turbo that referenced this pull request Nov 27, 2022
Closes [hotwired#794][]

Reverts the implementation change made in [hotwired#674][], and in
its place passes `shouldCacheSnapshot: false` alongside `willRender:
false` for the `action: "replace"` Visit proposed when following a
redirect.

In order to test this behavior, this commit introduces the
`readBodyMutationLogs` test utility function, along with the
`window.bodyMutationLogs` property and the `BodyMutationLog` type.

`BodyMutationLog` instances are pushed onto the log `Array` whenever the
`<body>` element is replaced.

[hotwired#794]: hotwired#794
[hotwired#674]: hotwired#674
seanpdoyle added a commit to seanpdoyle/turbo that referenced this pull request Dec 31, 2022
Closes [hotwired#794][]

Reverts the implementation change made in [hotwired#674][], and in
its place passes `shouldCacheSnapshot: false` alongside `willRender:
false` for the `action: "replace"` Visit proposed when following a
redirect.

In order to test this behavior, this commit introduces the
`readBodyMutationLogs` test utility function, along with the
`window.bodyMutationLogs` property and the `BodyMutationLog` type.

`BodyMutationLog` instances are pushed onto the log `Array` whenever the
`<body>` element is replaced.

[hotwired#794]: hotwired#794
[hotwired#674]: hotwired#674
seanpdoyle added a commit to seanpdoyle/turbo that referenced this pull request Dec 31, 2022
Closes [hotwired#794][]

Reverts the implementation change made in [hotwired#674][], and in
its place passes `shouldCacheSnapshot: false` alongside `willRender:
false` for the `action: "replace"` Visit proposed when following a
redirect.

In order to test this behavior, this commit introduces the
`readBodyMutationLogs` test utility function, along with the
`window.bodyMutationLogs` property and the `BodyMutationLog` type.

`BodyMutationLog` instances are pushed onto the log `Array` whenever the
`<body>` element is replaced.

[hotwired#794]: hotwired#794
[hotwired#674]: hotwired#674
dhh pushed a commit that referenced this pull request Jan 4, 2023
* Fix flaky Firefox tests

Some tests that visit the `navigation.html` fixture exercise scroll
behavior by visiting links and other content that is below the fold. The
`style="height: 200vh"` value declared on the page's `<section>` element
is arbitrary, but double the screen size to force content below the
fold.

Unluckily, it cuts off _right_ at the beginning of the new `<iframe>`
elements in Firefox browsers, which obscures the `<a>` element and
prevents link clicks.

To resolve that issue, this commit removes the `[style]` attribute,
since the content is long enough to be scrollable.

* Skip Snapshot Caching for redirect visits

Closes [#794][]

Reverts the implementation change made in [#674][], and in
its place passes `shouldCacheSnapshot: false` alongside `willRender:
false` for the `action: "replace"` Visit proposed when following a
redirect.

In order to test this behavior, this commit introduces the
`readBodyMutationLogs` test utility function, along with the
`window.bodyMutationLogs` property and the `BodyMutationLog` type.

`BodyMutationLog` instances are pushed onto the log `Array` whenever the
`<body>` element is replaced.

[#794]: #794
[#674]: #674
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants