From bb97bf68323fc8e839a396c55106425bf36ac221 Mon Sep 17 00:00:00 2001 From: Eric Baer Date: Fri, 11 May 2018 10:43:52 -0700 Subject: [PATCH 1/2] Ensure comparison of routes is tolerant of an initially undefined query --- lib/router/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/router/router.js b/lib/router/router.js index 5193be435b81..7529ee51f040 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -303,7 +303,7 @@ export default class Router { } urlIsNew (pathname, query) { - return this.pathname !== pathname || !shallowEquals(query, this.query) + return this.pathname !== pathname || !shallowEquals(query || {}, this.query || {}) } isShallowRoutingPossible (route) { From 786686afe1497588d2399a63442b13ce2c4c054e Mon Sep 17 00:00:00 2001 From: Eric Baer Date: Fri, 11 May 2018 16:34:39 -0700 Subject: [PATCH 2/2] Add test for server handled query change edge case --- test/unit/router.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unit/router.test.js b/test/unit/router.test.js index e9865d83e160..991323b32d9b 100644 --- a/test/unit/router.test.js +++ b/test/unit/router.test.js @@ -63,4 +63,14 @@ describe('Router', () => { expect(Object.keys(pageLoader.loaded)).toEqual(routes) }) }) + + describe('.urlIsNew()', () => { + it('should handle undefined starting query parameters', () => { + const pageLoader = new PageLoader() + const router = new Router('/', undefined, '/', { pageLoader }) + // This function will call shallowEqual with the query below and the undefined value set in + // the constructor. + router.urlIsNew('/', { queryVariable: '1' }) + }) + }) })