Skip to content
This repository has been archived by the owner on Jul 28, 2018. It is now read-only.

Fix page caching and lifecycle events #575

Merged
merged 1 commit into from
Jul 20, 2015
Merged

Conversation

Thibaut
Copy link
Collaborator

@Thibaut Thibaut commented Jul 20, 2015

Fix #551.

Partial replacement broke the page cache by caching body.outerHTML (losing all DOM state in the process) instead of the body element itself.

This PR brings back the old behavior, with the following drawback: when a partial replacement is performed, instead of caching the current page, 1) we don't cache it and 2) we remove it from the cache if it was there already (previous visit), since 1) the body element will not change and there is no simple way for us to bring back the changed nodes, 2) we don't want to restore an outdated version of the page.

Also:

  • page:after-remove on body elements now triggers on cache eviction (since we don't want to lose DOM state when restoring pages from the cache)
  • to avoid triggering page:load on the same body element more than once, which would be a major breaking change, partial replacements now trigger the page:partial-load event.

@dhh @reed @kristianpd @WojtekKruszewski

Fix turbolinks#551.

Partial replacement broke the page cache by caching body.outerHTML (losing all DOM
state in the process) instead of the body element itself.

This commit brings back the old behavior, with the following gotcha: when a partial
replacement is performed, we remove the current page from the cache, since the body
element will not change and there is no simple way for us to bring back the changed
nodes.

Additionally:

- page:after-remove on body elements now triggers on cache eviction (since we don't
  want to lose DOM state)
- to avoid triggering page:load on the same body elements more than once, a partial
  replacement now triggers the page:partial-load event
@Thibaut
Copy link
Collaborator Author

Thibaut commented Jul 20, 2015

Docs in #576.

dhh added a commit that referenced this pull request Jul 20, 2015
Fix page caching and lifecycle events
@dhh dhh merged commit 4f99d6c into turbolinks:master Jul 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants