-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[docs] Remove old workarounds #20587
Changes from all commits
ab9302f
a7030e5
e262548
b438d6f
b83ebae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'; | ||
import optionsReducer from 'docs/src/modules/redux/optionsReducer'; | ||
import { createLogger } from 'redux-logger'; | ||
|
||
// Get the Redux DevTools extension and fallback to a no-op function | ||
let devtools = (x) => x; | ||
|
@@ -13,7 +14,7 @@ if ( | |
devtools = window.__REDUX_DEVTOOLS_EXTENSION__(); | ||
} | ||
|
||
function create(initialState) { | ||
export default function create(initialState) { | ||
let middleware = []; | ||
|
||
if ( | ||
|
@@ -23,9 +24,6 @@ function create(initialState) { | |
// redux-logger needs this feature | ||
Object.hasOwnProperty('assign') | ||
) { | ||
// eslint-disable-next-line global-require | ||
const createLogger = require('redux-logger').createLogger; | ||
|
||
middleware = [...middleware, createLogger()]; | ||
} | ||
|
||
|
@@ -37,18 +35,3 @@ function create(initialState) { | |
compose(applyMiddleware(...middleware), devtools), | ||
); | ||
} | ||
|
||
export default function initRedux(initialState) { | ||
// Make sure to create a new store for every server-side request so that data | ||
// isn't shared between connections (which would be bad) | ||
if (!process.browser) { | ||
return create(initialState); | ||
} | ||
|
||
// Reuse store on the client-side | ||
if (!global.__INIT_REDUX_STORE__) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for context. The incentive for the global was to account for cases where Next.js doesn't bundle redux into the share JavaScript bundle. In the past, I had multiple cases where we would get a new instance of redux per page. I don't know if it's still a concern today. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would we get multiple instances? There's only a single store. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically, Next.js/webpack would fail to identify Redux as a module that needs to be put into the shared bundle. In some cases, we had:
the JavaScript reference doesn't match, we end-up with two Redux store loading when transitioning from page a to page b, page b has no prior knowledge of the store of page a. I imagine it can be reproduced in dev mode, where we only build one page at the time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if this were the case: What is the problem? These are pure functions (ignoring devtools). We can call them how often we want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And again: Every page could have its own module. We would still use the same store across pages since AppWrapper stays mounted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was causing an issue with the states that aren't persisted. For instance, if we store the dark theme into redux or the color of the page, we would lose it with the first page transition. As long as we don't notice a behavior in this order, I think it's safe to move forward. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To illustrate: You're seeing the flamegraph of the commit after we navigated from / to /components/box. "ne" is the AppWrapper component that got updated. It didn't "render for the first time" i.e. mount. What mounted was the page (the big yellow bar): The store wasn't re-created. That only happens when AppWrapper mounts which happens once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👌 |
||
global.__INIT_REDUX_STORE__ = create(initialState); | ||
eps1lon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return global.__INIT_REDUX_STORE__; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Webpack is clever enough to remove
redux-logger
from prod bundles (at least the bundle size didn't show that so it's either bundled anyway or working as expected). One less global require :)