Skip to content

fix(ui): return wrapped history in redux-remember unserialize #8317

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

Merged
merged 1 commit into from
Jul 21, 2025

Conversation

psychedelicious
Copy link
Collaborator

Summary

We intermittently get an error like this:

TypeError: Cannot read properties of undefined (reading 'length')

This error is caused by a redux-undo-enhanced slice being rehydrated without the extra stuff it adds to the slice to make it undoable (e.g. an array of past states, the present state, array of future states, and some other metadata).

redux-undo may need to check the length of the past/future arrays as part of its internal functionality. These keys don't exist so we get the error. I'm not sure why they don't exist - my understanding of redux-undo is that it should be checking and wrapping the state w/ the history stuff automatically. Seems to be related to redux-remember - may be a race condition.

The solution is to ensure we wrap rehydrated state for undoable slices as we rehydrate them. I discovered the solution while troubleshooting #8314 when the changes therein somehow triggered the issue to start occuring every time instead of rarely.

Related Issues / Discussions

This has popped up intermittently but I can only find 1 example in GH.

QA Instructions

Should be zero functionality changes. Not sure how to reproduce the issue.

Merge Plan

n/a

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

We intermittently get an error like this:
```
TypeError: Cannot read properties of undefined (reading 'length')
```

This error is caused by a `redux-undo`-enhanced slice being rehydrated
without the extra stuff it adds to the slice to make it undoable (e.g.
an array of `past` states, the `present` state, array of `future`
states, and some other metadata).

`redux-undo` may need to check the length of the past/future arrays as
part of its internal functionality. These keys don't exist so we get the
error. I'm not sure _why_ they don't exist - my understanding of
`redux-undo` is that it should be checking and wrapping the state w/ the
history stuff automatically. Seems to be related to `redux-remember` -
may be a race condition.

The solution is to ensure we wrap rehydrated state for undoable slices
as we rehydrate them. I discovered the solution while troubleshooting
#8314 when the changes therein somehow triggered the issue to start
occuring every time instead of rarely.
@github-actions github-actions bot added the frontend PRs that change frontend files label Jul 21, 2025
@psychedelicious psychedelicious merged commit 9d1f09c into main Jul 21, 2025
12 checks passed
@psychedelicious psychedelicious deleted the psyche/fix/ui-rehydration-error branch July 21, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend PRs that change frontend files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: TypeError: Cannot read properties of undefined (reading 'length')
3 participants