From 4bf81d8b7553394570ac419489e4e8f8b2d6c34c Mon Sep 17 00:00:00 2001 From: Eric Lambrecht Date: Tue, 19 Mar 2019 17:33:45 +0100 Subject: [PATCH] fix(redux): fixed location object, now including search and hash, too --- .../action-creator-dispatcher/mixin.server.js | 2 +- .../spec/integration/redux/__tests__/develop.js | 17 +++++++++++++++-- packages/spec/integration/redux/index.js | 4 ++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/redux/action-creator-dispatcher/mixin.server.js b/packages/redux/action-creator-dispatcher/mixin.server.js index 8358e60a5..12b0906c3 100644 --- a/packages/redux/action-creator-dispatcher/mixin.server.js +++ b/packages/redux/action-creator-dispatcher/mixin.server.js @@ -25,7 +25,7 @@ class ReduxActionCreatorServerMixin extends ReduxActionCreatorCommonMixin { async fetchData(data) { if (this.canPrefetchOnServer().every(value => value)) { - await this.dispatchAll(createLocation(this.request.path)); + await this.dispatchAll(createLocation(this.request.originalUrl)); this.prefetchedOnServer = true; } return data; diff --git a/packages/spec/integration/redux/__tests__/develop.js b/packages/spec/integration/redux/__tests__/develop.js index afc02eff8..8f3e0f933 100644 --- a/packages/spec/integration/redux/__tests__/develop.js +++ b/packages/spec/integration/redux/__tests__/develop.js @@ -41,6 +41,19 @@ describe('redux developmet server', () => { await page.close(); }); + it('executes route-matching action creators also if a search query or hash is present', async () => { + const { page, getInnerText } = await createPage(); + await page.goto(url + '/increment?foo=bar#hash', { + waitUntil: 'networkidle2', + }); + + const count = await getInnerText('counter'); + + expect(count).toBe('1'); + + await page.close(); + }); + it('executes route-matching action creators with fetch', async () => { const { page, getInnerText } = await createPage(); await page.goto(url + '/increment-fetch', { waitUntil: 'networkidle2' }); @@ -65,13 +78,13 @@ describe('redux developmet server', () => { it('executes route-matching action creators with react-router-location as part of their second argument', async () => { const { page, getInnerText } = await createPage(); - await page.goto(url + '/location-test', { + await page.goto(url + '/location-test?foo=bar', { waitUntil: 'networkidle2', }); const param = await getInnerText('value'); - expect(param).toBe('/location-test'); + expect(param).toBe('?foo=bar'); await page.close(); }); diff --git a/packages/spec/integration/redux/index.js b/packages/spec/integration/redux/index.js index bf2c98529..a21225bc0 100644 --- a/packages/spec/integration/redux/index.js +++ b/packages/spec/integration/redux/index.js @@ -34,10 +34,10 @@ const incrementFetch = () => dispatch => { const setParam = ({ param }) => ({ type: 'SET_VALUE', payload: param }); -const setLocationPathname = (params, { location: { pathname } }) => { +const setLocationPathname = (params, { location: { search } }) => { return { type: 'SET_VALUE', - payload: pathname, + payload: search, }; };