remix-run / history

Manage session history with JavaScript
MIT License
8.29k stars 961 forks source link

Restore entries attribute in MemoryHistory interface #939

Open Donorlin opened 2 years ago

Donorlin commented 2 years ago

Would feature fix this https://github.com/remix-run/history/issues/828

This PR gives back the feature of MemoryHistory.entries which was available in version 4

Many people are dependent on this feature, mainly because it gives more control over memory history itself.

For example, we are running SPA in the SSR (company historical reasons). This means the SPA state is lost whenever a site is reloaded. In version history@4 we are able to save entries from the history object and pass it to initialEntries of the MemoryRouter to seed it back to its previous state (controlled behavior).

In react-router@6 we are still able to access the MemoryHistory object with UNSAFE_NavigationContext, but not its entries. So we are not able to implement a controlled MemoryRouter.

If it was intentional to remove entries for API reasons, close this PR.

Thank you for your response.

Nantris commented 2 years ago

@mjackson could we get some clarity on this? We rely on being able to access history.entries and I know we're not alone from reading #828.

Is there some reason for removing this? Can we approve this PR to add it back? There was no indication this interface was going to be removed and so no reason people would have been hesitant to rely on it - but now we're locked in the past on version 4.x unless either:

Nantris commented 2 years ago

It's also not mentioned as something that was removed, as far as I can tell:

If there's no hard blockers here, I really hope we can get this merged.

Nantris commented 2 years ago

Could we get a reply on this, even if the answer is no to merging? We need clarity on this.

@mjackson

Nantris commented 2 years ago

Could we just get a comment on why it was removed? Please?

It would be awful to go through the work of forking this library to expose entries just to find out there's some good reason it's not exposed anymore. As far as I can tell, it was just removed without mention or reason, but I really don't want to stake hours of time on that and be wrong.

Nantris commented 2 years ago

@chaance sorry to tag you, but I hoped maybe you could provide clarity here as substantial recent contributor.

Nantris commented 2 years ago

Can anyone provide clarity on this? Why not merge this PR?

chaance commented 2 years ago

@Slapbox We've been busy with other priorities, and Michael has to review/approve API changes. These things sometimes take time. If you can't wait, there's always patch-package.

Nantris commented 2 years ago

Friendly bump.

Nantris commented 2 years ago

Friendly bump. I'd love to get our project up to date and using the latest react-router, but this is a blocker for us and the PR is ultra-minimalist. I hope it can be approved soon.

Nantris commented 2 years ago

Friendly bump. We remain hesitant to use patch-package in case there's some reason that the entries property was removed from MemoryHistory, although that seems unlikely since it's not in the patch notes.

JarekToro commented 1 year ago

Bump

Nantris commented 1 year ago

I've given up hope on React Router at this point.

Donorlin commented 1 year ago

It looks like this package is not even used by react-router anymore. Pardon me if I am wrong. I am using only github for browsing router packages. All history implementation is now here @remix-run/router and createMemoryRouter is here packages/router/history.ts#L214. Sadly still no entries are exported even though it is more or less the same implementation.

Later today, maybe tommorow, I will recreate this PR for missing entries. Wish us luck.

Donorlin commented 1 year ago

looks like there already was a PR with this change https://github.com/remix-run/react-router/pull/10499 but got closed.

Apparently this is viewed as a new feature and it should go through their Open Development Process.

Please make some polite noice at this open discussion for this "new" feature https://github.com/remix-run/react-router/discussions/9853