diff --git a/src/main/frontend/worker/pipeline.cljs b/src/main/frontend/worker/pipeline.cljs index 018e03dcd6..72b9bb4376 100644 --- a/src/main/frontend/worker/pipeline.cljs +++ b/src/main/frontend/worker/pipeline.cljs @@ -125,9 +125,12 @@ (not (ldb/inline-tag? (:block/raw-title entity) tag)) (not (:db/ident entity))) (let [eid (:db/id entity)] - [[:db/add eid :db/ident (db-class/create-user-class-ident-from-name db-after (:block/title entity))] - [:db/add eid :logseq.property.class/extends :logseq.class/Root] - [:db/retract eid :block/tags :logseq.class/Page]]) + (if (:block/page entity) + ;; Built-in #Tag should never turn a page child block into a class. + [[:db/retract eid :block/tags :logseq.class/Tag]] + [[:db/add eid :db/ident (db-class/create-user-class-ident-from-name db-after (:block/title entity))] + [:db/add eid :logseq.property.class/extends :logseq.class/Root] + [:db/retract eid :block/tags :logseq.class/Page]])) ;; remove #Page from tags/journals etc. (= (:db/id page-tag) (:v datom)) diff --git a/src/test/frontend/worker/pipeline_test.cljs b/src/test/frontend/worker/pipeline_test.cljs index 18587c1e04..c64753063b 100644 --- a/src/test/frontend/worker/pipeline_test.cljs +++ b/src/test/frontend/worker/pipeline_test.cljs @@ -3,6 +3,7 @@ [datascript.core :as d] [frontend.worker.pipeline :as worker-pipeline] [logseq.db :as ldb] + [logseq.db.common.order :as db-order] [logseq.db.test.helper :as db-test])) (deftest test-built-in-page-updates-that-should-be-reverted @@ -143,3 +144,46 @@ :block/title "page1-renamed"}])] (is (= "page1-renamed" (:block/title (d/entity (:db-after result) (:db/id page1))))))))) + +(deftest built-in-tag-must-not-convert-page-child-block-to-class-test + (let [conn (db-test/create-conn-with-blocks + {:pages-and-blocks [{:page {:block/title "page1"}}]}) + page1 (ldb/get-page @conn "page1") + now (js/Date.now) + bad-block-uuid (random-uuid) + new-tag-uuid (random-uuid)] + (ldb/register-transact-pipeline-fn! worker-pipeline/transact-pipeline) + + (testing "page-child block with built-in #Tag stays a block" + (ldb/transact! conn [{:block/uuid bad-block-uuid + :block/title "charlie" + :block/created-at now + :block/updated-at now + :block/page (:db/id page1) + :block/parent (:db/id page1) + :block/order (db-order/gen-key) + :block/tags [:logseq.class/Tag]}]) + (let [block (d/entity @conn [:block/uuid bad-block-uuid])] + (is (some? block)) + (is (nil? (:db/ident block))) + (is (nil? (:logseq.property.class/extends block))) + (is (not (ldb/class? block))) + (is (= (:db/id page1) (:db/id (:block/parent block)))) + (is (empty? (:block/tags block))))) + + (testing "standalone candidate is still converted to a class page" + (ldb/transact! conn [{:block/uuid new-tag-uuid + :block/name "standalone-tag" + :block/title "standalone-tag" + :block/created-at now + :block/updated-at now + :block/tags [:logseq.class/Tag]}]) + (let [tag-page (d/entity @conn [:block/uuid new-tag-uuid])] + (is (ldb/class? tag-page)) + (is (keyword? (:db/ident tag-page))) + (is (= "user.class" (namespace (:db/ident tag-page)))) + (is (= [:logseq.class/Root] + (map :db/ident (:logseq.property.class/extends tag-page)))))) + + ;; return global fn back to previous behavior + (ldb/register-transact-pipeline-fn! identity)))