From b34259af615b5aacb30a88ae2bb912760a9789d2 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Fri, 29 Sep 2017 11:14:31 -0700 Subject: [PATCH 1/2] Fix issue where router would initialize before primaryShopId was avalable. - Revert back to using subscription manager. - Add a check to wait on reactive var `Reaction.primaryShopId` in addition to the subscriptions before initializing the router. --- imports/plugins/core/router/client/startup.js | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/imports/plugins/core/router/client/startup.js b/imports/plugins/core/router/client/startup.js index 47d7df0ffd1..81525d599f6 100644 --- a/imports/plugins/core/router/client/startup.js +++ b/imports/plugins/core/router/client/startup.js @@ -4,28 +4,29 @@ import { Tracker } from "meteor/tracker"; import { Accounts } from "meteor/accounts-base"; import { Shops } from "/lib/collections"; import { initBrowserRouter } from "./browserRouter"; +import { Reaction } from "/client/api"; import { Router } from "../lib"; Meteor.startup(function () { loadRegisteredComponents(); - // Subscribe to router required publications - // Note: Although these are subscribed to by the subscription manager in "/modules/client/core/subscriptions", - // using the subscriptions manager sometimes causes issues when signing in/out where you may seee a grey screen - // or missing shop data throughout the app. - // TODO: Revisit subscriptions manager usage and waiting for shops to exist client side before rendering. - const primaryShopSub = Meteor.subscribe("PrimaryShop"); - const merchantShopSub = Meteor.subscribe("MerchantShops"); - const packageSub = Meteor.subscribe("Packages"); - Tracker.autorun(function () { // initialize client routing - if (primaryShopSub.ready() && merchantShopSub.ready() && packageSub.ready()) { + if ( + Reaction.Subscriptions.Packages.ready() && + Reaction.Subscriptions.PrimaryShop.ready() && + Reaction.Subscriptions.MerchantShops.ready() && + // In addition to the subscriptions, shopId must be defined before we proceed + // to avoid conditions where the subscriptions may be ready, but the cached + // shopId has yet been set. + // Reaction.primaryShopId is a reactive data source + Reaction.primaryShopId !== null + ) { const shops = Shops.find({}).fetch(); // initBrowserRouter calls Router.initPackageRoutes which calls shopSub.ready which is reactive, // So we have to call initBrowserRouter in a non reactive context. // Otherwise initBrowserRouter is called twice each time a subscription becomes "ready" - Tracker.nonreactive(()=> { + Tracker.nonreactive(() => { // Make sure we have shops before we try to make routes for them if (Array.isArray(shops) && shops.length) { initBrowserRouter(); From 67d0a0361048cfea7316a319964c69260c37a810 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Fri, 29 Sep 2017 11:31:44 -0700 Subject: [PATCH 2/2] Reintroduce local router subscriptions to fix the sign-in-out issues Reintroduce local subscriptions in thr router startup to fix the resurfaced issues with a blank screen and missing shops on sign in/out. This, with the addition of the check for primaryShopId, fixes issues for both sign in/out as well as hard refreshes. --- imports/plugins/core/router/client/startup.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/imports/plugins/core/router/client/startup.js b/imports/plugins/core/router/client/startup.js index 81525d599f6..7f75a796cd2 100644 --- a/imports/plugins/core/router/client/startup.js +++ b/imports/plugins/core/router/client/startup.js @@ -10,12 +10,21 @@ import { Router } from "../lib"; Meteor.startup(function () { loadRegisteredComponents(); + // Subscribe to router required publications + // Note: Although these are subscribed to by the subscription manager in "/modules/client/core/subscriptions", + // using the subscriptions manager sometimes causes issues when signing in/out where you may seee a grey screen + // or missing shop data throughout the app. + // TODO: Revisit subscriptions manager usage and waiting for shops to exist client side before rendering. + const primaryShopSub = Meteor.subscribe("PrimaryShop"); + const merchantShopSub = Meteor.subscribe("MerchantShops"); + const packageSub = Meteor.subscribe("Packages"); + Tracker.autorun(function () { // initialize client routing if ( - Reaction.Subscriptions.Packages.ready() && - Reaction.Subscriptions.PrimaryShop.ready() && - Reaction.Subscriptions.MerchantShops.ready() && + primaryShopSub.ready() && + merchantShopSub.ready() && + packageSub.ready() && // In addition to the subscriptions, shopId must be defined before we proceed // to avoid conditions where the subscriptions may be ready, but the cached // shopId has yet been set.