Skip to content
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

[Tech] Remove the Global State #3827

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Conversation

CommandMC
Copy link
Collaborator

@CommandMC CommandMC commented Jun 17, 2024

The GlobalState / ContextProvider is now replaced with a Zustand store, which improves the re-rendering issues dramatically

The commits here are quite bite-sized, so reviewing them one at a time is recommended. The commit messages also include details in case something was out of the ordinary when migrating that specific property

Known issues:

  • Library changes following user action (game install, update, uninstall, etc) take a longer time to update, I assume there was some optimistic UI here that I didn't migrate
  • ...probably more! Still have to test this on a clean-install & on multiple OSs

Use the following Checklist if you have changed something on the Backend or Frontend:

  • Tested the feature and it's working on a current and clean install.
  • Tested the main App features and they are still working on a current and clean install. (Login, Install, Play, Uninstall, Move games, etc.)
  • Created / Updated Tests (If necessary)
  • Created / Updated documentation (If necessary)

We already have this available globally on `window`, so we don't need it in the
context provider as well
This also simplifies the logic for setting languages, as the component setting
it now only has to call `setLanguage` & everything will update on its own
I'd recommend turning on the "Hide whitespace" option in GitHub's diff view for
this commit
Note that storing this as an object is not a good idea, since `useShallow`
checks for equality with `Object.is` (so when updating `helpItems`, we'd have to
create a new `help` object, which would also cause re-renders for components
only using `addHelpItem` / `removeHelpItem`)
@CommandMC CommandMC added the pr:wip WIP, don't merge. label Jun 17, 2024
@CommandMC CommandMC self-assigned this Jun 17, 2024
This was definitely the biggest change yet. Most of it was just taking a
`runner` everywhere (to build a key to index into the record)

This still has one issue (the library isn't refreshed after a game
install/update finishes), it'll be resolved by future commits. Still, this
should be a noticeable speed boost
I've chosen to inherit from the `ExperimentalFeatures` interface here to make
picking out the values from the state easier. Otherwise, you'd need something
like this for each one:
```
const enableNewDesign = useGlobalState(useShallow((state) => state
.experimentalFeatures.enableNewDesign))
```
which is rather verbose
This being a global function living on `window` was unnecessary as far as I
could tell, and we can just implement it with a normal function being
auto-called if `theme` updates
This also modifies `InstallModal` to live on the Root & render based on only
`installModalOptions`, like our other modals/dialogs do
We can just do this on the one component calling this function

This also introduces a local `refreshing` state for the Wine Manager, as the
global state's is intended as a library refresh state
…deloadedLibrary`

Quite a big commit, but splitting this up further isn't possible
@CommandMC CommandMC changed the title [Tech] Remove more properties from the Global Context [Tech] Remove the Global State Jun 23, 2024
@CommandMC CommandMC marked this pull request as ready for review June 23, 2024 14:41
@CommandMC CommandMC added pr:testing This PR is in testing, don't merge. pr:ready-for-review Feature-complete, ready for the grind! :P and removed pr:wip WIP, don't merge. labels Jun 23, 2024
@CommandMC CommandMC requested review from a team, arielj, flavioislima, Etaash-mathamsetty, Nocccer and imLinguin and removed request for a team June 23, 2024 14:42
@arielj
Copy link
Collaborator

arielj commented Jul 10, 2024

something seems to be wrong with the global state after uninstalling a game, when I try to close heroic it thinks it's still doing something and shows the heroic is performing an operation, do you want to close it anyway message

image

there's no way to make these changes more gradually? I know I always say the same but it's really hard to review 100 files changing, this changes a lot around the whole app, it's impossible for us to test/QA everything properly

a nice thing that I liked about zustand was that it would allow us to move things to zustand gradually in different PRs with more focused scope to focus the test instead of changing everything, I'm always scared of changing that much

I understand the commits are more granular, but everything in a single PR would block all the changes that are working because of issues in other places

@CommandMC
Copy link
Collaborator Author

Part of why I was so granular with these commits is so we can take only a part of them and merge those. I'll create a new PR with some of the "easy" changes here, if that's easier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:ready-for-review Feature-complete, ready for the grind! :P pr:testing This PR is in testing, don't merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants