Niedzielski has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398913 )

Change subject: Fix: only render the last requested route
......................................................................

Fix: only render the last requested route

Route.getProps() resolves asynchronously. Only render the result if the
requested route is not outdated at resolution. This bug was causing the
wrong page to be displayed for the wrong path when quickly jumping
between pages.

Change-Id: Id49febf245f21a03290fdef32de6f7d3e6788bbd
---
M src/client/index.tsx
M src/common/router/router.ts
2 files changed, 23 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/13/398913/1

diff --git a/src/client/index.tsx b/src/client/index.tsx
index ea10080..6d3ef39 100644
--- a/src/client/index.tsx
+++ b/src/client/index.tsx
@@ -38,7 +38,15 @@
 }
 
 function route(location: Location | HistoricalLocation) {
-  router.route(location.pathname, location.search).then(renderPageRoot);
+  const path = location.pathname;
+  const query = location.search;
+  router.route(path, query).then(rsp => {
+    // Routing is asynchronous. If a previous route resolves late, don't render
+    // it if the client has already moved on.
+    if (router.path() === path && router.query() === query) {
+      renderPageRoot(rsp);
+    }
+  });
 }
 
 // Observe the History
diff --git a/src/common/router/router.ts b/src/common/router/router.ts
index af9a47b..7c48161 100644
--- a/src/common/router/router.ts
+++ b/src/common/router/router.ts
@@ -102,8 +102,22 @@
   routes: Route<any>[],
   requestPageModule: RequestPageModule = requestPageModuleChunk
 ) {
+  let routedPath: string | undefined;
+  let routedQuery: string | undefined;
   return {
+    /** The last URL path routed. */
+    path(): string | undefined {
+      return routedPath;
+    },
+
+    /** The last URL query routed. */
+    query(): string | undefined {
+      return routedQuery;
+    },
+
     route(path: string, query?: string): Promise<RouteResponse<any>> {
+      routedPath = path;
+      routedQuery = query;
       const pathQuery = `${path}${query || ""}`;
       for (const route of routes) {
         const params = route.toParams(path, query);

-- 
To view, visit https://gerrit.wikimedia.org/r/398913
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id49febf245f21a03290fdef32de6f7d3e6788bbd
Gerrit-PatchSet: 1
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to