Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

MM-24009: remove redux-offline #1396

Merged
merged 16 commits into from
Mar 17, 2021
Merged

Conversation

lieut-data
Copy link
Member

@lieut-data lieut-data commented Mar 5, 2021

Summary

Follow the lead of mattermost/mattermost-mobile#4120 and remove redux-offline. The library was responsible for automatically retrying select requests, but the vast majority of API calls remained unaffected. Removing the library simplifies the surface area of the Redux store and corresponding code. Note that this library is discrete from redux-persist, currently responsible for the magic of storage.storage and rehydrating previously saved drafts, etc.

I've broken this PR into various discrete PRs that are worth reviewing independently. But to summarize the other changes that were tangled with removing this library:

  • Replace remote-redux-devtools with redux-devtools-extension -- the former has support for React Native apps and routing requests through remotedev.io, but none of this is needed for the WebApp now that Mattermost Redux is unused by the mobile app.
  • Fix frozen stores in development: after peeling back the layers of code, it looked like freezing the Redux store in development wasn't actually working. This is completed by corresponding changes in the WebApp.

Ticket Link

Fixes: https://mattermost.atlassian.net/browse/MM-24009

Also, see mattermost/mattermost-webapp#7648

@lieut-data lieut-data added 2: Dev Review Requires review by a core commiter 3: QA Review labels Mar 5, 2021
src/actions/channels.ts Outdated Show resolved Hide resolved
src/actions/posts.ts Outdated Show resolved Hide resolved
src/actions/preferences.ts Outdated Show resolved Hide resolved
src/store/configureStore.dev.ts Show resolved Hide resolved
src/actions/posts.ts Show resolved Hide resolved
src/actions/preferences.ts Outdated Show resolved Hide resolved
src/store/configureStore.dev.ts Show resolved Hide resolved
* getAppReducer - A function that returns the appReducer as defined above. Only used in development to enable hot reloading.
* clientOptions - An object containing additional options used when configuring the redux store. The following options are available:
* additionalMiddleware - func | array - Allows for single or multiple additional middleware functions to be passed in from the client side.
* enableThunk - bool - default = true - If true, include the thunk middleware automatically. If false, thunk must be provided as part of additionalMiddleware.
*/
export default function configureServiceStore(preloadedState: any, appReducer: any, userOfflineConfig: any, getAppReducer: any, clientOptions: any) {
const baseOfflineConfig = Object.assign({}, defaultOfflineConfig, offlineConfig, userOfflineConfig);
export default function configureServiceStore(preloadedState: any, appReducer: any, persistConfig: any, getAppReducer: any, clientOptions: any): Store {
Copy link
Member

Choose a reason for hiding this comment

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

Strictly speaking, this is a breaking change for anyone using mattermost-redux to configure their own store. This isn't one of the areas I think we've really implied backwards compatibility though. If we ever do that, we should make this take named arguments in an object instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed re: breaking change, and that we're not explicitly supporting backwards compatibility here. I'm not really sure we should, either, but open for debate!

});
}

return store;
}

function createDevReducer(baseState: any, ...reducers: any) {
return enableFreezing(createReducer(baseState, ...reducers));
return createReducer(baseState, ...reducers);
Copy link
Member

Choose a reason for hiding this comment

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

Why move enableFreezing out of here? It looks like you're always calling them together anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooh, good catch -- when I originally removed createOfflineReducer, I started getting exceptions around the store being mutated. So to isolate and fix that, I called them in the order enableFreezing(createOfflineReducer(createDevReducer)) and made sure freezing worked before ripping out createOfflineReducer afterwards. The final delta is unnecessary, though -- and in fact createDevReducer is largely superfluous at this point.

In fact, I'm not entirely convinced it's necessary to distinguish .dev.ts from .prod.ts in the first place, given tree-shaking and what not. Either way, I'll clean up this anomaly.

@lieut-data
Copy link
Member Author

/update-branch

src/actions/posts.ts Outdated Show resolved Hide resolved
@lieut-data lieut-data requested a review from hmhealey March 8, 2021 21:40
@hmhealey hmhealey removed the 2: Dev Review Requires review by a core commiter label Mar 9, 2021
@hmhealey hmhealey requested a review from jgilliam17 March 9, 2021 16:35
@hmhealey
Copy link
Member

hmhealey commented Mar 9, 2021

@jgilliam17 This has to be reviewed in the corresponding webapp PR

@hmhealey hmhealey added the Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) label Mar 9, 2021
@hmhealey
Copy link
Member

hmhealey commented Mar 9, 2021

@lieut-data I've added the Awaiting PR label since if this goes in first and someone updates their version of mattermost-redux in the webapp, then it'll break due to the change in parameters. One of the many reasons I'm looking forward to getting rid of mattermost-redux

@lieut-data
Copy link
Member Author

Re-requesting dev review given the changes. Might be easiest to review with whitespace diff disabled. See mattermost/mattermost-webapp#7648 (comment) for context.

@lieut-data lieut-data removed the request for review from jgilliam17 March 12, 2021 19:23
@lieut-data lieut-data added the 2: Dev Review Requires review by a core commiter label Mar 12, 2021
src/actions/channels.ts Show resolved Hide resolved
src/actions/channels.test.js Outdated Show resolved Hide resolved
src/actions/posts.ts Show resolved Hide resolved
@lieut-data lieut-data removed Do Not Merge/Awaiting PR Awaiting another pull request before merging (e.g. server changes) 3: QA Review labels Mar 17, 2021
@lieut-data lieut-data added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core commiter labels Mar 17, 2021
@lieut-data lieut-data merged commit a9a44d5 into master Mar 17, 2021
@lieut-data lieut-data deleted the mm-24009-remove-redux-offline branch March 17, 2021 17:12
@tkiethanom
Copy link

It doesn't look like this change was pushed to the npm version 5.33.1. I'm still seeing redux-offline in the dependencies list.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants