From 06e59b92ef987ae6097fe71e0e0d670fd156430f Mon Sep 17 00:00:00 2001 From: J Atkin Date: Tue, 21 May 2024 18:29:43 +0100 Subject: [PATCH] Add cache busting to inputs --- src/main/com/fulcrologic/fulcro/dom/inputs.cljc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/com/fulcrologic/fulcro/dom/inputs.cljc b/src/main/com/fulcrologic/fulcro/dom/inputs.cljc index becb834d..00f19ed4 100644 --- a/src/main/com/fulcrologic/fulcro/dom/inputs.cljc +++ b/src/main/com/fulcrologic/fulcro/dom/inputs.cljc @@ -35,25 +35,28 @@ (let [{:keys [value onChange]} (comp/props this) nsv (evt/target-value evt) nv (string->model nsv)] - (comp/set-state! this {:stringValue nsv - :oldPropValue value - :value nv}) + (comp/set-state! this {:stringValue nsv + :oldPropValue value + :cacheValue nv + :cacheInvalid? false}) (when (and onChange (not= value nv)) (onChange nv)))) - :stringValue (model->string value)}] + :stringValue (model->string value) + :cacheInvalid? true}] (set! (.-state this) (cljs.core/js-obj "fulcro$state" initial-state))) nil)))] (comp/configure-component! cls kw {:getDerivedStateFromProps (fn [latest-props state] (let [{:keys [value]} latest-props - {:keys [oldPropValue stringValue]} state - ignorePropValue? (or (= oldPropValue value) (= value (:value state))) + {:keys [oldPropValue stringValue cacheValue cacheInvalid?]} state + ignorePropValue? (or (= oldPropValue value) (when-not cacheInvalid? (= value cacheValue))) + cacheInvalid? (or cacheInvalid? ignorePropValue?) stringValue (cond-> (if ignorePropValue? stringValue (model->string value)) string-filter string-filter) - new-derived-state (merge state {:stringValue stringValue :oldPropValue value})] + new-derived-state (merge state {:stringValue stringValue :oldPropValue value :cacheInvalid? cacheInvalid?})] #js {"fulcro$state" new-derived-state})) :render (fn [this]