Skip to content

Commit

Permalink
Merge pull request #2982 from reactioncommerce/mm-fix-issue-2975
Browse files Browse the repository at this point in the history
Fix issue where router would initialize before primaryShopId was available
  • Loading branch information
kieckhafer authored Sep 29, 2017
2 parents 74dd10e + bde7ab1 commit 1f5cc5f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion imports/plugins/core/router/client/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 () {
Expand All @@ -20,7 +21,16 @@ Meteor.startup(function () {

Tracker.autorun(function () {
// initialize client routing
if (primaryShopSub.ready() && merchantShopSub.ready() && packageSub.ready()) {
if (
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.
// 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.
Expand Down

0 comments on commit 1f5cc5f

Please sign in to comment.