|
| 1 | +- Start Date: 2016/12/05 |
| 2 | +- RFC PR: (leave this empty) |
| 3 | +- Ember Issue: (leave this empty) |
| 4 | + |
| 5 | +# Summary |
| 6 | + |
| 7 | +Track unique history location states |
| 8 | + |
| 9 | +# Motivation |
| 10 | + |
| 11 | +The path alone does not provide enough information. For example, if you |
| 12 | +visit page A, scroll down, then click on a link to page B, then click on |
| 13 | +a link back to page A. Your actual browser history stack is [A, B, A]. |
| 14 | +Each of those nodes in the history should have their own unique scroll |
| 15 | +position. In order to record this position we need a UUID |
| 16 | +for each node in the history. |
| 17 | + |
| 18 | +This API will allow other libraries to reflect upon each location to |
| 19 | +determine unique state. For example, |
| 20 | +[ember-router-scroll](https://github.com/dollarshaveclub/ember-router-scroll) |
| 21 | +is making use of a [modified `Ember.HistoryLocation` object to get this |
| 22 | +behavior](https://github.com/dollarshaveclub/ember-router-scroll/blob/master/addon/locations/router-scroll.js). |
| 23 | + |
| 24 | +Tracking unique state is required when setting the scroll position |
| 25 | +properly based upon where you are in the history stack, as described in |
| 26 | +[Motivation](#motivation) |
| 27 | + |
| 28 | +# Detailed design |
| 29 | + |
| 30 | +Code: [PR#14011](https://github.com/emberjs/ember.js/pull/14011) |
| 31 | + |
| 32 | +We simply unique identifier (UUID) so we can track uniqueness on two |
| 33 | +dimensions. Both `path` and the generated `uuid`. A simple UUID |
| 34 | +generator such as |
| 35 | +https://gist.github.com/lukemelia/9daf074b1b2dfebc0bd87552d0f6a537 |
| 36 | +should suffice. |
| 37 | + |
| 38 | +# How We Teach This |
| 39 | + |
| 40 | +We could describe what meta data is generated for each location in the |
| 41 | +history stack. For example, it could look like: |
| 42 | + |
| 43 | +```js |
| 44 | +// visit page A |
| 45 | + |
| 46 | +[ |
| 47 | + { path: '/', uuid: 1 } |
| 48 | +] |
| 49 | + |
| 50 | +// visit page B |
| 51 | + |
| 52 | +[ |
| 53 | + { path: '/about', uuid: 2 }, |
| 54 | + { path: '/', uuid: 1 } |
| 55 | +] |
| 56 | + |
| 57 | +// visit page A |
| 58 | + |
| 59 | +[ |
| 60 | + { path: '/', uuid: 3 }, |
| 61 | + { path: '/about', uuid: 2 }, |
| 62 | + { path: '/', uuid: 1 } |
| 63 | +] |
| 64 | + |
| 65 | +// click back button |
| 66 | + |
| 67 | +[ |
| 68 | + { path: '/about', uuid: 2 }, |
| 69 | + { path: '/', uuid: 1 } |
| 70 | +] |
| 71 | +``` |
| 72 | + |
| 73 | +# Drawbacks |
| 74 | + |
| 75 | +* The property access is writable |
| 76 | + |
| 77 | +# Alternatives |
| 78 | + |
| 79 | +The purpose for this behavior is to enable scroll position libraries. |
| 80 | +There are two other solutions in the wild. One is in the guides that |
| 81 | +suggests resetting the scroll position to `(0, 0)` on each new route |
| 82 | +entry. The other is |
| 83 | +[ember-memory-scroll](https://github.com/ef4/memory-scroll) which I |
| 84 | +believe is better suited for tracking scroll positions for components |
| 85 | +rather than the current page. |
| 86 | + |
| 87 | +However, in both cases neither solution provides the experience that |
| 88 | +users have come to expect from server-rendered pages. The browser tracks |
| 89 | +scroll position and restores it when you revisit the page in the history |
| 90 | +stack. The scroll position is unique even if you have multiple instances |
| 91 | +of the same page in the stack. |
| 92 | + |
| 93 | +# Unresolved questions |
| 94 | + |
| 95 | +None at this time. |
0 commit comments