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

Remove stale elements before cache #238

Merged
merged 2 commits into from
Jun 16, 2021
Merged

Conversation

ayrton
Copy link
Contributor

@ayrton ayrton commented Apr 12, 2021

Some content is inherently stale the moment you've shown it to users. Eg in Ruby on Rails it's common that you use flash messages to communicate a message from your controller to your users.

When a user navigates away and returns to the original page, turbo will briefly show cached content:

Screen.Recording.2021-02-09.at.12.35.57.mov

This PR adds a hook by adding data-turbo-cache="false" to individual dom elements to remove them from Turbo's cache.

--

Originally posted about the issue in hotwired/turbo-rails#117

@dhh
Copy link
Member

dhh commented Jun 8, 2021

I dig this. Can you add a test?

@ayrton
Copy link
Contributor Author

ayrton commented Jun 16, 2021

I dig this. Can you add a test?

Added tests:

✓ firefox on mac 20.3.0 - CacheObserverTests - removes stale elements (0.621s)

Let me know if something's still missing.

@dhh dhh merged commit 7a894fe into hotwired:main Jun 16, 2021
packagethief added a commit that referenced this pull request Feb 14, 2023
Renames the `[data-turbo-cache=false]` attribute (used to denote temporary
elements that should be removed before caching) to `[data-turbo-temporary]` for
better similarity with `[data-turbo-permanent]`, its conceptual opposite.

This is a superficial change, but worth it in terms of cohesion, I think. The
pairing of "temporary" with "permanent" is just too good to ignore. Also, given
the existence of `turbo-cache-*` as the namespace for page-level cache control,
a unique name is less likely to confuse.

References:
- #238
packagethief added a commit that referenced this pull request Feb 14, 2023
Renames the `[data-turbo-cache=false]` attribute (used to denote temporary
elements that should be removed before caching) to `[data-turbo-temporary]` for
better similarity with `[data-turbo-permanent]`, its conceptual opposite.

This is a superficial change, but worth it in terms of cohesion, I think. The
pairing of "temporary" with "permanent" is just too good to ignore. Also, given
the existence of `turbo-cache-*` as the namespace for page-level cache control,
a unique name is less likely to confuse.

References:
- #238
dhh pushed a commit that referenced this pull request Feb 15, 2023
…#871)

Renames the `[data-turbo-cache=false]` attribute (used to denote temporary
elements that should be removed before caching) to `[data-turbo-temporary]` for
better similarity with `[data-turbo-permanent]`, its conceptual opposite.

This is a superficial change, but worth it in terms of cohesion, I think. The
pairing of "temporary" with "permanent" is just too good to ignore. Also, given
the existence of `turbo-cache-*` as the namespace for page-level cache control,
a unique name is less likely to confuse.

References:
- #238
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