Skip to content

Conversation

psychedelicious
Copy link
Collaborator

@psychedelicious psychedelicious commented Sep 4, 2025

Summary

While working on something else, I noticed there was some extra data in the params slice that was left-over Invoke v6 (x/y coords). This data was added when we created the Generate tab and gave it its own width and height settings, separate from Canvas. The bbox logic from Canvas was copied over, but we didn't remove the x/y coords.

I removed this data, added a migration, and then noticed there was an issue w/ state rehydration that caused the params slice to be reset. After some investigation I noticed that there was a design issue with state rehydration and redux slice migration in some rare scenarios. I fixed it in this PR.

Fixing this cleanly has a knock-on effect - when adding data to a redux slice, you must write a slice migration, else rehydration will fail and reset the user's data! I've updated the PR template so we are reminded to not miss this step when making changes in the future.

Related Issues / Discussions

n/a

QA Instructions

n/a

Merge Plan

n/a

Checklist

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

@github-actions github-actions bot added CI-CD Continuous integration / Continuous delivery frontend PRs that change frontend files labels Sep 4, 2025
@psychedelicious psychedelicious changed the title tidy(ui): remove unused coords from params slice tidy,fix(ui): remove unused coords from params slice Sep 4, 2025
@psychedelicious psychedelicious enabled auto-merge (rebase) September 5, 2025 01:24
Certain items in redux are ephemeral and omitted from persisted slices.
On rehydration, we need to inject these values back into the slice.

But there was an issue taht could prevent slice migrations from running
during rehydration.

The migrations look for the `_version` key in state and migrate the
slice accordingly.

The logic that merged in the ephemeral values accidentally _also_ merged
in the `_version` key if it didn't already exist. This happened _before_
migrations are run.

This causes problems for slices that didn't have a `_version` key and
then have one added via migration.

For example, the params slice didn't have a `_version` key until the
previous commit, which added `_version` and changed some other parts of
state in a migration.

On first load of the updated code, we have a catch-22 kinda situation:
- The persisted params slice is the old version. It needs to have both
`_version` and some other data added to it.
- We deserialize the state and then merge in ephemeral values. This
inadvertnetly also merged in the `_version` key.
- We run the slice migration. It sees there is a `_version` key and
thinks it doesn't need to run. The extra data isn't added to the slice.
The slice is parsed against its zod schema and fails because the new
data is missing.
- Because the parse failed, we treat the user's persisted data as
invalid and overwrite it with initial state, potentially causing data
loss.

The fix is to be more selective when merging in the ephemeral state
before migration - this is now done by checking which keys are on the
persist denylist and only adding those key.
@psychedelicious psychedelicious force-pushed the psyche/tidy/ui/remove-unused-coords-from-params-slice branch from 32cc5b4 to 2f46664 Compare September 5, 2025 01:24
@psychedelicious psychedelicious merged commit 20d57d5 into main Sep 5, 2025
13 checks passed
@psychedelicious psychedelicious deleted the psyche/tidy/ui/remove-unused-coords-from-params-slice branch September 5, 2025 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-CD Continuous integration / Continuous delivery frontend PRs that change frontend files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants