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

[Redux Toolkit Migration] Use new Redux Toolkit configureStore API #4000

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

joel-jeremy
Copy link
Contributor

@joel-jeremy joel-jeremy commented Dec 17, 2024

Initial migration to redux-toolkit. This PR focuses on retrofitting the existing reducers to the newer redux toolkit APIs. We can work on converting them to redux slices in a future PR.

Aside from converting to the usage of typed useAppDispatcher and useAppSelector, I had to do some changes to the SET_LAST_UNDO_STATE and SET_LAST_SPLIT_STATE to prevent mutating the state in their reducers because redux toolkit now check for that.

There are still some redux validation errors due to non-serializable values being on the the state e.g. modal callback functions. But I have disabled those checks temporarily until we can address them in a future PR.

  • Use redux toolkit's configureStore API
  • Address Redux Immutability Middleware errors in reducers (SET_LAST_UNDO_STATE, SET_LAST_SPLIT_STATE)
  • Address Redux Serializability Middleware errors in reducers (e.g. modal callback functions)
  • Update reducers to use new redux toolkit createSlice API
  • Update actions to use new redux toolkit createAsyncThunk API

@actual-github-bot actual-github-bot bot changed the title Initial upgrade to redux toolkit [WIP] Initial upgrade to redux toolkit Dec 17, 2024
Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit dd92cb3
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/6764a09c3f538500081d0a8a
😎 Deploy Preview https://deploy-preview-4000.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Dec 17, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
10 5.53 MB → 5.54 MB (+4.53 kB) +0.08%
Changeset (largest 100 files by percent change)
File Δ Size
node_modules/redux/dist/redux.mjs 🆕 +8.33 kB 0 B → 8.33 kB
node_modules/react-redux/dist/react-redux.mjs 🆕 +7.44 kB 0 B → 7.44 kB
node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.mjs 🆕 +5.07 kB 0 B → 5.07 kB
node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js 🆕 +2.59 kB 0 B → 2.59 kB
home/runner/work/actual/actual/packages/loot-core/src/client/store/index.ts 🆕 +988 B 0 B → 988 B
node_modules/redux-thunk/dist/redux-thunk.mjs 🆕 +375 B 0 B → 375 B
node_modules/use-sync-external-store/with-selector.js 🆕 +122 B 0 B → 122 B
src/redux/index.ts 🆕 +95 B 0 B → 95 B
node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js?commonjs-exports 🆕 +53 B 0 B → 53 B
node_modules/use-sync-external-store/with-selector.js?commonjs-module 🆕 +33 B 0 B → 33 B
src/hooks/useFailedAccounts.ts 📈 +123 B (+129.47%) 95 B → 218 B
src/hooks/useUpdatedAccounts.ts 📈 +3 B (+3.09%) 97 B → 100 B
src/hooks/useAccounts.ts 📈 +9 B (+2.97%) 303 B → 312 B
src/hooks/usePayees.ts 📈 +18 B (+2.91%) 619 B → 637 B
src/hooks/useCategories.ts 📈 +9 B (+2.86%) 315 B → 324 B
home/runner/work/actual/actual/packages/loot-core/src/platform/client/undo/index.web.ts 📈 +17 B (+2.35%) 724 B → 741 B
src/hooks/useSyncedPrefs.ts 📈 +6 B (+2.07%) 290 B → 296 B
src/hooks/useSyncedPref.ts 📈 +6 B (+1.78%) 337 B → 343 B
src/hooks/useActions.ts 📈 +3 B (+1.73%) 173 B → 176 B
node_modules/clsx/dist/clsx.m.js 📈 +6 B (+1.73%) 347 B → 353 B
src/hooks/useMetadataPref.ts 📈 +6 B (+1.69%) 354 B → 360 B
src/hooks/useGlobalPref.ts 📈 +6 B (+1.42%) 424 B → 430 B
node_modules/react/index.js 📈 +2 B (+1.39%) 144 B → 146 B
src/hooks/useModalState.ts 📈 +9 B (+1.36%) 664 B → 673 B
src/hooks/useSyncServerStatus.ts 📈 +3 B (+1.24%) 241 B → 244 B
node_modules/@use-gesture/react/dist/use-gesture-react.esm.js 📈 +6 B (+1.03%) 580 B → 586 B
home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/dashboard.ts 📈 +2 B (+0.84%) 239 B → 241 B
home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/widget.ts 📈 +2 B (+0.72%) 278 B → 280 B
src/components/reports/ReportOptions.ts 📈 +46 B (+0.68%) 6.56 kB → 6.61 kB
src/components/reports/disabledList.ts 📈 +18 B (+0.46%) 3.84 kB → 3.86 kB
node_modules/@react-aria/overlays/dist/useModal.mjs 📈 +14 B (+0.44%) 3.13 kB → 3.14 kB
node_modules/@react-aria/ssr/dist/SSRProvider.mjs 📈 +14 B (+0.38%) 3.61 kB → 3.63 kB
node_modules/react-aria-components/dist/Popover.mjs 📈 +18 B (+0.34%) 5.11 kB → 5.13 kB
node_modules/@react-aria/overlays/dist/Overlay.mjs 📈 +8 B (+0.34%) 2.31 kB → 2.32 kB
node_modules/@react-aria/collections/dist/CollectionBuilder.mjs 📈 +36 B (+0.32%) 11.07 kB → 11.1 kB
node_modules/react-aria-components/dist/Form.mjs 📈 +6 B (+0.31%) 1.88 kB → 1.89 kB
src/hooks/useUndo.ts 📈 +3 B (+0.30%) 992 B → 995 B
node_modules/@react-aria/interactions/dist/PressResponder.mjs 📈 +6 B (+0.28%) 2.1 kB → 2.11 kB
node_modules/@react-aria/overlays/dist/DismissButton.mjs 📈 +4 B (+0.28%) 1.41 kB → 1.42 kB
node_modules/@react-aria/utils/dist/useLayoutEffect.mjs 📈 +2 B (+0.27%) 738 B → 740 B
node_modules/react-aria-components/dist/Modal.mjs 📈 +18 B (+0.26%) 6.88 kB → 6.89 kB
node_modules/@react-aria/interactions/dist/context.mjs 📈 +2 B (+0.25%) 800 B → 802 B
src/components/UpdateNotification.tsx 📈 +9 B (+0.25%) 3.58 kB → 3.59 kB
src/components/manager/ManagementApp.tsx 📈 +15 B (+0.24%) 6.07 kB → 6.09 kB
node_modules/@react-aria/collections/dist/Hidden.mjs 📈 +8 B (+0.24%) 3.26 kB → 3.27 kB
node_modules/react-aria-components/dist/Tooltip.mjs 📈 +12 B (+0.23%) 5.08 kB → 5.09 kB
node_modules/@react-aria/focus/dist/useFocusable.mjs 📈 +6 B (+0.23%) 2.54 kB → 2.54 kB
node_modules/react-simple-pull-to-refresh/build/index.esm.js 📈 +32 B (+0.23%) 13.83 kB → 13.86 kB
node_modules/@react-aria/i18n/dist/context.mjs 📈 +2 B (+0.21%) 952 B → 954 B
src/components/LoggedInUser.tsx 📈 +6 B (+0.21%) 2.85 kB → 2.86 kB
src/components/modals/BudgetListModal.tsx 📈 +3 B (+0.20%) 1.45 kB → 1.45 kB
node_modules/react-aria-components/dist/ListBox.mjs 📈 +36 B (+0.20%) 17.48 kB → 17.51 kB
src/components/AppBackground.tsx 📈 +3 B (+0.20%) 1.46 kB → 1.46 kB
node_modules/react-aria-components/dist/Header.mjs 📈 +2 B (+0.17%) 1.12 kB → 1.12 kB
node_modules/react-aria-components/dist/Dialog.mjs 📈 +8 B (+0.17%) 4.65 kB → 4.65 kB
src/components/BankSyncStatus.tsx 📈 +3 B (+0.16%) 1.84 kB → 1.85 kB
node_modules/@react-stately/collections/dist/CollectionBuilder.mjs 📈 +14 B (+0.15%) 8.84 kB → 8.86 kB
node_modules/react-aria-components/dist/Collection.mjs 📈 +4 B (+0.15%) 2.66 kB → 2.66 kB
node_modules/react-aria-components/dist/DragAndDrop.mjs 📈 +6 B (+0.14%) 4.06 kB → 4.07 kB
src/components/HelpMenu.tsx 📈 +3 B (+0.13%) 2.28 kB → 2.28 kB
src/components/settings/Reset.tsx 📈 +3 B (+0.13%) 2.3 kB → 2.3 kB
src/components/Notifications.tsx 📈 +9 B (+0.13%) 6.97 kB → 6.98 kB
src/components/mobile/accounts/Accounts.tsx 📈 +9 B (+0.12%) 7.47 kB → 7.48 kB
src/components/mobile/accounts/AccountTransactions.tsx 📈 +9 B (+0.12%) 7.49 kB → 7.5 kB
node_modules/react-markdown/lib/react-markdown.js 📈 +6 B (+0.12%) 5.01 kB → 5.01 kB
src/components/reports/spreadsheets/net-worth-spreadsheet.ts 📈 +4 B (+0.11%) 3.4 kB → 3.4 kB
src/components/reports/spreadsheets/makeQuery.ts 📈 +2 B (+0.11%) 1.75 kB → 1.76 kB
src/components/App.tsx 📈 +6 B (+0.11%) 5.32 kB → 5.33 kB
src/components/transactions/TransactionMenu.tsx 📈 +3 B (+0.11%) 2.69 kB → 2.69 kB
src/components/sidebar/Sidebar.tsx 📈 +3 B (+0.11%) 2.76 kB → 2.76 kB
src/components/manager/subscribe/Bootstrap.tsx 📈 +3 B (+0.10%) 2.86 kB → 2.87 kB
src/components/modals/CoverModal.tsx 📈 +3 B (+0.10%) 2.86 kB → 2.87 kB
src/components/modals/OutOfSyncMigrationsModal.tsx 📈 +3 B (+0.10%) 2.86 kB → 2.87 kB
src/components/mobile/budget/CategoryTransactions.tsx 📈 +3 B (+0.10%) 2.92 kB → 2.92 kB
src/components/modals/manager/FilesSettingsModal.tsx 📈 +6 B (+0.10%) 6 kB → 6.01 kB
src/components/sidebar/BudgetName.tsx 📈 +3 B (+0.09%) 3.27 kB → 3.27 kB
src/components/modals/MergeUnusedPayeesModal.tsx 📈 +6 B (+0.09%) 6.55 kB → 6.56 kB
src/components/modals/EnvelopeBudgetSummaryModal.tsx 📈 +3 B (+0.09%) 3.31 kB → 3.31 kB
node_modules/@react-aria/visually-hidden/dist/VisuallyHidden.mjs 📈 +2 B (+0.09%) 2.23 kB → 2.23 kB
src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx 📈 +6 B (+0.09%) 6.8 kB → 6.81 kB
node_modules/react-router-dom/dist/index.js 📈 +10 B (+0.09%) 11.34 kB → 11.35 kB
src/components/schedules/index.tsx 📈 +3 B (+0.08%) 3.59 kB → 3.59 kB
src/components/schedules/ScheduleLink.tsx 📈 +3 B (+0.08%) 3.65 kB → 3.65 kB
node_modules/react-aria-components/dist/Button.mjs 📈 +4 B (+0.08%) 4.9 kB → 4.9 kB
src/components/schedules/PostsOfflineNotification.tsx 📈 +3 B (+0.08%) 3.69 kB → 3.7 kB
src/components/modals/manager/ImportYNAB5Modal.tsx 📈 +3 B (+0.07%) 3.97 kB → 3.98 kB
src/components/modals/manager/ImportYNAB4Modal.tsx 📈 +3 B (+0.07%) 3.97 kB → 3.98 kB
src/components/modals/TransferModal.tsx 📈 +3 B (+0.07%) 4.04 kB → 4.04 kB
src/components/manager/WelcomeScreen.tsx 📈 +3 B (+0.07%) 4.06 kB → 4.06 kB
src/components/settings/Encryption.tsx 📈 +3 B (+0.07%) 4.06 kB → 4.06 kB
src/components/reports/spreadsheets/summary-spreadsheet.ts 📈 +4 B (+0.07%) 5.67 kB → 5.68 kB
node_modules/react-markdown/lib/ast-to-react.js 📈 +6 B (+0.07%) 8.57 kB → 8.57 kB
src/components/reports/reports/CustomReportListCards.tsx 📈 +3 B (+0.07%) 4.28 kB → 4.29 kB
src/components/modals/manager/ImportActualModal.tsx 📈 +3 B (+0.07%) 4.38 kB → 4.38 kB
src/components/modals/manager/ImportModal.tsx 📈 +3 B (+0.07%) 4.4 kB → 4.41 kB
src/components/modals/LoadBackupModal.tsx 📈 +3 B (+0.06%) 5.01 kB → 5.01 kB
src/components/transactions/TransactionList.jsx 📈 +3 B (+0.06%) 5.22 kB → 5.22 kB
src/components/FinancesApp.tsx 📈 +6 B (+0.06%) 10.61 kB → 10.62 kB
src/components/modals/manager/DeleteFileModal.tsx 📈 +3 B (+0.05%) 5.33 kB → 5.33 kB
src/components/manager/subscribe/Login.tsx 📈 +3 B (+0.05%) 5.34 kB → 5.34 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/ReportRouter.js 1.58 MB → 1.58 MB (+3.17 kB) +0.20%
static/js/index.js 3.45 MB → 3.46 MB (+1.54 kB) +0.04%
static/js/narrow.js 83.36 kB → 83.38 kB (+27 B) +0.03%

Smaller

Asset File Size % Changed
static/js/TransactionList.js 102.91 kB → 102.79 kB (-118 B) -0.11%
static/js/wide.js 161.25 kB → 161.16 kB (-91 B) -0.06%

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/resize-observer.js 18.37 kB 0%

Copy link
Contributor

github-actions bot commented Dec 17, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.32 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.32 MB 0%

@joel-jeremy
Copy link
Contributor Author

/update-vrt

@@ -11,6 +11,7 @@ const currentUndoState: T.UndoState = {
url: null,
openModal: null,
selectedItems: null,
current: null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from redux state.app.lastUndoState to here

@@ -8,6 +8,7 @@ export type UndoState = {
name: string;
items: Set<string>;
} | null;
current: unknown;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from redux state.app.lastUndoState to here

// Reset the state and only keep around things intentionally. This
// blows away everything else
state = {
account: initialAccountState,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS is complaining about the missing state properties so I have set them to initial states instead.

@@ -1,7 +1,7 @@
import type * as constants from '../constants';

export type AccountState = {
failedAccounts: Map<string, { type: string; code: string }>;
failedAccounts: { [key: string]: { type: string; code: string } };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to object because redux toolkit complains that Map is non-serializable

@@ -18,17 +16,6 @@ export function update(state = initialState, action: Action): AppState {
...state,
...action.state,
};
case constants.SET_LAST_UNDO_STATE:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from redux state and moved to loot-core/platform/client/undo since redux toolkit is complaining that it's mutating in the reducer

state.lastUndoState.current = action.undoState;
return state;

case constants.SET_LAST_SPLIT_STATE:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from redux state and moved to useSplitExpanded since redux toolkit is complaining that it's mutating in the reducer

@@ -2,8 +2,8 @@ import * as constants from '../constants';
import type { Action } from '../state-types';
import type { AccountState } from '../state-types/account';

const initialState: AccountState = {
failedAccounts: new Map(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from Map to object since redux toolkit is complaining that Map is non-serializable

@@ -59,7 +59,7 @@ type SplitsStateContext = {
const SplitsExpandedContext = createContext<SplitsStateContext>({
state: {
mode: 'collapse',
ids: new Set(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from Set to array since redux toolkit is complaining that Set is non-serializable

@joel-jeremy joel-jeremy changed the title [WIP] Initial upgrade to redux toolkit Upgrade to redux toolkit (Part 1) Dec 18, 2024
@joel-jeremy joel-jeremy changed the title Upgrade to redux toolkit (Part 1) [Redux Toolkit Migration] Use new Redux Toolkit configureStore API Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant