From 14366ccce3a1fadc3f8e2c238bd827dab4ecbfa3 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Mon, 2 May 2016 20:18:58 +0200 Subject: [PATCH] Flush ratom queue before rendering Make sure outstanding reactions etc are up-to-date. --- src/reagent/dom.cljs | 3 +++ src/reagent/dom/server.cljs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/reagent/dom.cljs b/src/reagent/dom.cljs index d6e05af..0e86ba7 100644 --- a/src/reagent/dom.cljs +++ b/src/reagent/dom.cljs @@ -2,6 +2,7 @@ (:require [cljsjs.react.dom] [reagent.impl.util :as util] [reagent.impl.template :as tmpl] + [reagent.ratom :as ratom] [reagent.debug :refer-macros [dbg]] [reagent.interop :refer-macros [$ $!]])) @@ -45,6 +46,7 @@ ([comp container] (render comp container nil)) ([comp container callback] + (ratom/flush!) (let [f (fn [] (tmpl/as-element (if (fn? comp) (comp) comp)))] (render-comp f container callback)))) @@ -70,6 +72,7 @@ ClojureScript). To get around this you'll have to introduce a layer of indirection, for example by using `(render [#'foo])` instead." [] + (ratom/flush!) (doseq [v (vals @roots)] (apply re-render-component v)) "Updated") diff --git a/src/reagent/dom/server.cljs b/src/reagent/dom/server.cljs index 0bdb14e..4e3bd1f 100644 --- a/src/reagent/dom/server.cljs +++ b/src/reagent/dom/server.cljs @@ -2,6 +2,7 @@ (:require [cljsjs.react.dom.server] [reagent.impl.util :as util] [reagent.impl.template :as tmpl] + [reagent.ratom :as ratom] [reagent.interop :refer-macros [$ $!]])) (defonce ^:private imported nil) @@ -20,11 +21,13 @@ (defn render-to-string "Turns a component into an HTML string." [component] + (ratom/flush!) (binding [util/*non-reactive* true] ($ (module) renderToString (tmpl/as-element component)))) (defn render-to-static-markup "Turns a component into an HTML string, without data-react-id attributes, etc." [component] + (ratom/flush!) (binding [util/*non-reactive* true] ($ (module) renderToStaticMarkup (tmpl/as-element component))))