Browse Source

fix: cycle refs

Tienson Qin 8 months ago
parent
commit
ed648af845

+ 1 - 1
deps/db/src/logseq/db/common/entity_plus.cljc

@@ -98,7 +98,7 @@
          (let [result (lookup-entity e k default-value)
                ;; Replace title for pages only, otherwise it'll recursively
                ;; replace block id refs if there're cycle references of blocks
-               refs (filter common-entity-util/page? (:block/refs e))
+               refs (:block/refs e)
                result' (if (and (string? result) refs)
                          ;; FIXME: Correct namespace dependencies instead of resolve workaround
                          ((resolve 'logseq.db.frontend.content/id-ref->title-ref) result refs search?)

+ 4 - 2
deps/db/src/logseq/db/frontend/content.cljs

@@ -4,6 +4,7 @@
             [datascript.core :as d]
             [logseq.common.util :as common-util]
             [logseq.common.util.page-ref :as page-ref]
+            [logseq.db.common.entity-util :as common-entity-util]
             [logseq.db.frontend.entity-util :as entity-util]))
 
 ;; [[uuid]]
@@ -40,8 +41,9 @@
 
 (defn id-ref->title-ref
   "Convert id ref backs to page name refs using refs."
-  [content* refs search?]
-  (let [content (str content*)]
+  [content* refs* search?]
+  (let [refs (filter common-entity-util/page? refs*)
+        content (str content*)]
     (if (re-find id-ref-pattern content)
       (reduce
        (fn [content ref]

+ 17 - 15
src/main/frontend/components/block.cljs

@@ -1266,9 +1266,12 @@
         block-type (keyword (pu/lookup block :logseq.property/ls-type))
         hl-type (pu/lookup block :logseq.property.pdf/hl-type)
         repo (state/get-current-repo)
-        stop-inner-events? (= block-type :whiteboard-shape)]
+        stop-inner-events? (= block-type :whiteboard-shape)
+        config' (assoc config
+                       :block-ref? true
+                       :stop-events? stop-inner-events?)]
     (if (and block (:block/title block))
-      (let [content-cp (block-content (assoc config :block-ref? true :stop-events? stop-inner-events?)
+      (let [content-cp (block-content config'
                                       block nil (:block/uuid block)
                                       (:slide? config)
                                       nil)
@@ -1334,7 +1337,9 @@
 (rum/defc block-reference
   [config id label]
   (let [block-id (and id (if (uuid? id) id (parse-uuid id)))
-        [block set-block!] (hooks/use-state (db/entity [:block/uuid block-id]))]
+        [block set-block!] (hooks/use-state (db/entity [:block/uuid block-id]))
+        self-reference? (when (set? (:ref-set config))
+                          (contains? (:ref-set config) block-id))]
     (hooks/use-effect!
      (fn []
        (p/let [block (db-async/<get-block (state/get-current-repo)
@@ -1343,9 +1348,10 @@
                                            :skip-refresh? true})]
          (set-block! block)))
      [])
-    (when-not (= block-id (:source-block-id config)) ; self reference
+    (when-not self-reference?
       (if block
-        (block-reference-aux config block label)
+        (let [config' (update config :ref-set (fn [s] (conj (set s) block-id)))]
+          (block-reference-aux config' block label))
         (invalid-node-ref block-id)))))
 
 (defn- render-macro
@@ -2871,24 +2877,21 @@
         format (if db-based? :markdown (or (:block/format block) :markdown))
         pre-block? (when-not db-based? (:block/pre-block? block))
         collapsed? (:collapsed? config)
-        content* (if db-based?
-                   (:block/raw-title block)
-                   (property-util/remove-built-in-properties format (:block/raw-title block)))
-        content (if-let [source-id (:source-block-id config)]
-                  (string/replace content* (ref/->block-ref source-id) "")
-                  content*)
+        content (if db-based?
+                  (:block/raw-title block)
+                  (property-util/remove-built-in-properties format (:block/raw-title block)))
+        content (if (string? content) (string/trim content) "")
+        block-ref? (:block-ref? config)
         block (merge block (block/parse-title-and-body uuid format pre-block? content))
         ast-body (:block.temp/ast-body block)
         ast-title (:block.temp/ast-title block)
         block (assoc block :block/title content)
         plugin-slotted? (and config/lsp-enabled? (state/slot-hook-exist? uuid))
-        block-ref? (:block-ref? config)
         stop-events? (:stop-events? config)
         block-ref-with-title? (and block-ref? (not (state/show-full-blocks?)) (seq ast-title))
         block-type (or
                     (pu/lookup block :logseq.property/ls-type)
                     :default)
-        content (if (string? content) (string/trim content) "")
         mouse-down-key (if (util/ios?)
                          :on-click
                          :on-pointer-down) ; TODO: it seems that Safari doesn't work well with on-pointer-down
@@ -3823,8 +3826,7 @@
            (set-block! block)))
        []))
     (when (or (:view? config) (:block/title block))
-      (let [config' (assoc config :source-block-id (:block/uuid block))]
-        (loaded-block-container config' block opts)))))
+      (loaded-block-container config block opts))))
 
 (defn divide-lists
   [[f & l]]