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

Fix hot reloading issues by removing the store from window #324

Conversation

DanielOrtel
Copy link
Contributor

Fixes #317

}

const initStore = <S extends Store>({makeStore, context, config}: InitStoreOptions<S>): S => {
const storeKey = getStoreKey(config);
let store: any;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this may not even be necessary, but it's probably a good idea to keep a global reference around in case getInitialProps is called client side. Far as I could test, client side getInitialProps used the existing store and state

@@ -214,7 +214,6 @@ The `createWrapper` function accepts `makeStore` as its first argument. The `mak

`createWrapper` also optionally accepts a config object as a second parameter:

- `storeKey` (optional, string) : the key used on `window` to persist the store on the client
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is no longer necessary

@@ -118,7 +115,7 @@ export const createWrapper = <S extends Store>(makeStore: MakeStore<S>, config:
callback: GetServerSidePropsCallback<S, P>,
): GetServerSideProps<P> => async context => await getStaticProps(callback as any)(context); // just not to repeat myself

const withRedux = (Component: NextComponentType | App | any) => {
const withRedux: (Component: NextComponentType | App | any) => NextComponentType | App | any = Component => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

type inference couldn't properly figure it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nevermind, ended up reverting the change. Explicit typing is too much of a headache here, since it could be either Page or App, so a consumer would always need to specify which.

const wrapper = createWrapper(makeStore, {storeKey: 'testStoreKey'});
const Page = () => null;
Page.getInitialProps = wrapper.getInitialPageProps(store => () => null);
test('store is available when calling getInitialProps client-side and references the existing store on client', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking this is sufficient to test the store is the same on client-side getInitialProps

@DanielOrtel DanielOrtel force-pushed the fix-hot-reloading branch 2 times, most recently from e516388 to 63f8648 Compare February 11, 2021 22:12
@kirill-konshin
Copy link
Owner

Great job. Thank you. I will review and merge shortly.

@kirill-konshin kirill-konshin merged commit 12cd3d7 into kirill-konshin:types-enchancements Apr 17, 2021
kirill-konshin added a commit that referenced this pull request Apr 17, 2021
* Fix #280
* Fix #207
* Minor fixes
* Updated API
* Updated versions
* Update README.md
* Fixed demos & tests
* Github Action
* Make demo-dynamic private
* Fix #326
* Fix hot reloading issues by removing the store from window (#324)

Co-authored-by: Melanie Seltzer <melleh11@gmail.com>
Co-authored-by: Daniel Ferenc Balogh <danielferencortel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants