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

User state lost in packState/unpackState #140

Closed
devonray opened this issue Feb 24, 2017 · 4 comments
Closed

User state lost in packState/unpackState #140

devonray opened this issue Feb 24, 2017 · 4 comments
Labels

Comments

@devonray
Copy link

It's clear that router.result contains only custom data specified in the routes hash, but it's not clear how to dynamically persist custom data to history.

My specific use case revolves around storing scroll state in the history entry in order to support browser back/forward navigation while preserving scroll position for paginated lists. In v13 both packState and unpackState utils support the state attribute, but it seems like it's getting stripped on the locationDidChange action at https://github.com/FormidableLabs/redux-little-router/blob/v13.0.0-0/src/enhancer.js#L36, perhaps due to the absence of state from the Location type definition.

Given that state seems to be supported throughout much of the code base I presume this was an unintentional omission from the resulting location descriptor, but I wanted to ask for clarification.

@tptee
Copy link
Contributor

tptee commented Mar 14, 2017

Hey @devonray, this definitely looks like a regression! I'll ping you with a new alpha that fixes this.

@tptee tptee added the bug label Mar 23, 2017
@tptee tptee changed the title Support for state? User state lost in packState/unpackState Mar 23, 2017
@devonray
Copy link
Author

devonray commented Mar 28, 2017

Upon further inspection I realize I may have misrepresented the root problem. There seem to be two orthogonal problems that led to my confusion and initial inquiry:

  1. When updating router.state the new state is not immediately reflected in the store. Repro steps:
    a. navigate: push(urlA)
    b. update scroll state: replace({}, { state: { scroll: {...} } })
    c. router.state == {} // expected router.state == { scroll: {...} }
    d. navigate: push(urlB)
    e. router.state == {}
    f. navigate back: back()
    g. router.state == { scrollState: {...} } // Note now the state is available
  2. When updating router.state the new state is destructively replaced. Repro steps (assuming the first issue above is fixed so we can immediately inspect state):
    a. persist some state: replace({}, { state: { someState } })
    b. router.state == { someState }
    c. persist some other state: replace({}, { state: { someOtherState } })
    d. router.state == { someOtherState } // expected router.state == { someState, someOtherState }

I could see a case for the second issue working as designed. The first issue, however, seems like a bug.

@codeincontext
Copy link

Did you find a solution to this? We're trying to store a scroll position with each item in the history

@tptee
Copy link
Contributor

tptee commented Jun 30, 2017

Should be fixed in v14.0.0-1! Give me a shout if you still run into issues.

@tptee tptee removed the in progress label Jun 30, 2017
@tptee tptee closed this as completed Jun 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants