   (cond
     (nil? cljs.env/*compiler*) changed-ns-syms'
     (false? (:recompile-dependents state))
-    (union (keep (fn [n] (:name (ana-api/find-ns n))) changed-ns-syms')
-           (find-figwheel-always))
+    (topo-sort
+     (reverse (union (keep (fn [n] (:name (ana-api/find-ns n))) changed-ns-syms')
+                     (find-figwheel-always))))
+
     :else
     (let [changed-ns-syms       (set (keep (fn [n] (:name (ana-api/find-ns n))) changed-ns-syms'))
           dependants            (set (mapcat

        :eval-body (slurp %)})
   (dependency-files st)))

(def ^:dynamic *transitive-dep-cache* false)

(defn transitive-dependents [nm]
  (let [cached (get-in @*transitive-dep-cache* (name nm))]
    (if (not (nil? cached))
      cached
      (let [res (set (ana/ns-dependents nm))]
        (swap! *transitive-dep-cache* assoc (name nm) res)
        res))))

(defn topo-compare [nm nm2]
  (cond
    (= nm nm2) 0
    (get (transitive-dependents nm) nm2) -1
    :else 1))

(defn mark-changed-ns [state ns-syms]
  (mapv (fn [nm]

                     (if (target-file-changed? state nm) true false)))
        ns-syms))

(defn find-figwheel-always []
  (set (filter (fn [n] (-> n meta :figwheel-always)) (ana-api/all-ns))))

