Skip to content

fix: file:// image paths, #alias of a tag, Validate graph report, PDF viewer after reload - #13897

Open
yuxi-liu-wired wants to merge 9 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-last
Open

yuxi-liu-wired wants to merge 9 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-last

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes logseq/db-test#1386. Fixes logseq/db-test#1450. Fixes logseq/db-test#1067. Fixes logseq/db-test#1384.

Four independent fixes, one commit each (branch fix/dbtest-last, based on master d06ded9). Each commit has a test that fails on master and passes with the fix. #1075, #1452 and #997 are not in this PR; the reasons are at the end.

#1386: images with %20 in a file:// URL (Electron)

What the user sees: ![x](file:///tmp/path%20spaces/qa%20image.png) shows a broken image; the same file with literal spaces renders.

Cause: mldoc parses the target as ["Complex" {:protocol "file" :link "/tmp/path%20spaces/qa%20image.png"}] and string-of-url returned the link with its percent-escapes. The image code treats that as a native path and file-path->assets-url encodes it again, so the request was assets:///tmp/path%2520spaces/....

Change: string-of-url (block.cljs) decodes the path of a file link with common-util/safe-decode-uri-component (a malformed escape such as a lone % is left as written). The same fix applies to file: links that open a file, which got the same %20 path.

Tests: frontend.components.block.file-url-test: decoded path, single-encoded assets:// URL, literal spaces, lone %.

#1450: #alias-of-a-tag offers "Convert to tag" and makes a separate tag

What the user sees: with tag Example Tag aliased ET, typing #ET offers Convert "ET" to tag first and not Example Tag. Choosing it makes ET a tag of its own and tags the block #ET, so the block is missing from Example Tag's table and queries.

Cause (three parts, all confirmed in the code and by the tests):

  • search-pages decides from :block/alias-source-page-class?, but <get-block never returns that key (it is only set for a map with :block/_alias, plain_value.cljs), so the guard never fired.
  • tag-on-chosen-handler converted the page before resolving the alias source, so its fallback that swaps in the aliased tag no longer applied afterwards.
  • get-all-classes returned each class's :block/alias as {:db/id} only (a nested entity crosses the worker boundary with just the attributes read so far), so get-matched-classes had no alias title to match #ET against.

Change: search-pages asks the worker for the alias source (<get-alias-source-page) and marks the typed page when it is a tag, so Convert is not offered. tag-on-chosen-handler skips the conversion for an alias of a tag; the existing swap then tags the block with the real tag. get-all-classes sends :db/id, :block/uuid and :block/title for each alias.

Tests: tag-search-does-not-convert-class-aliases (editor_test) now uses the real <get-block shape; hashtag-convert-page-to-tag-skips-alias-of-a-tag-test (page_test); get-all-classes-sends-alias-titles-for-tag-completion (worker property_test; round-trips the result through transit like the thread API).

Not checked at runtime: I did not click through the # popup in Electron.

#1067: "Validate graph" repairs blocks without saying so

What the user sees: validation with fix on (default) repairs invalid blocks, sometimes retracting attributes or deleting entities, then reports :errors nil / "Your graph is valid!". Only the errors are logged.

Cause: validate-and-fix-invalid-blocks! loops fix-invalid-blocks! until nothing is left and returns only the last (clean) round.

Change: each applied fix is logged at :debug next to the errors; the result gains :fixed-entity-ids (the entities the repair tx-data targeted, not every datom the pipeline stamped, only when non-empty); the notification is the i18n key :graph.validation/fixed-invalid-blocks with the count (pluralized in en.edn, other locales fall back to English) instead of "Your graph is valid!".

Tests: validate-db-reports-the-blocks-it-repaired (result ids, notification key and rendered text for 1 and 2 blocks, second run reports nothing) and validate-db-reports-only-the-blocks-it-targeted (a valid block referencing the repaired one is not counted).

Not decided here: whether the :db/retractEntity branches (e.g. "External URL") should exist at all; that is a maintainer call. The five other when fix passes are #1068.

#1384: PDF viewer blank after reload

What the user sees: after Ctrl+R on a page with a PDF, opening the PDF gives an empty left pane and the toolbar over the app header; navigating away and back repairs it.

Cause: body[data-page] gates the PDF viewer layout (pdf.css). update-page-label! sets it from the route title read through the db-worker. On reload the first route match runs before the db-worker exists; <invoke-db-worker throws "db-worker has not been initialized" and nothing sets the attribute until the next navigation.

Change: update-page-label! waits until the db-worker is up and the graph restore has finished (:db/restoring? cleared, exposed as frontend.flows/db-restoring?, the flag the header, sidebar and container already wait on), then labels the current route. Waiting for the worker alone is too early: on a reload the worker is installed before the graph is open, and the title would resolve to Logseq.

Tests: page-label-is-set-once-db-worker-is-ready-test and page-label-waits-for-the-graph-to-be-restored-test.

Test: page-label-is-set-once-db-worker-is-ready-test. On master it fails with the thrown "db-worker has not been initialized".

Not checked at runtime: I did not reload Electron with a PDF open; the cause comes from the code path and the test above.

Proof

  • Main bundle: the fixed sources were reverted together and the test bundle rebuilt; the new tests fail without the fixes (file-url-test 2 failures, editor-test 1, page-test 1 failure + 1 error, worker property-test 1, db-validate-test 2, route-test 1), pass with them, and pnpm cljs:run-test on the final tree has 0 failures, 0 errors. I used one combined revert instead of prove-fix.sh per file.
  • clj-kondo on all changed files: 0 errors, 0 warnings; typos clean.

Not in this PR

  • 页面引用出现属性块 #1075 (rename onto a recycled page's title): does not reproduce on this master. outliner-page/delete! re-parents the page under the Recycle page, and the duplicate query for a top-level page only matches pages with no parent (and for a namespaced page, siblings with the same parent), so a recycled page never matches. I checked with validate-block-title after outliner-page/delete! for an ordinary page and for a tagged page; both pass on master. The report is probably from before the recycle bin. If a case that still fails is found, note that fix(db): sync checksum and local graphs, page and tag names, orphaned pages, tag deletion, recycled values, and unreachable code #13786 changes the same query. Restoring a recycled page does not check for a live page with the same title, which this issue would make reachable if it did reproduce.
  • 是否支持daily journal 自定义文件路径 #1452 (#Asset tag hidden when "Hide from Node" is off): needs a maintainer's choice. tags-cp hides ldb/internal-tags unconditionally, and :logseq.class/Asset is in that set on purpose ("Built-in classes that are hidden on a node and all pages view"; it is also a private tag). #Asset also has hide-from-node true by default, so the toggle is redundant for it today. Honouring the toggle is a one-line change in tags-cp (do not treat Asset as an internal tag there), but it changes a documented behaviour.
  • 手机ios不push了 #997 (page properties ignore the beginning/end UI position): intentional on this master. display-properties skips the "other position" filter when page-properties-area? is true; that was added deliberately in aca15fa "fix: property ux regressions" (Jun 23, the build the reporter says still worked). Reverting it for pages is a product decision, and it needs a decision on where such properties would show on a page.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

Devin Review

Comment thread src/main/frontend/handler/route.cljs Outdated
Comment on lines +262 to +266
(add-watch state/db-worker-ready? ::update-page-label
(fn [_key _ref _old ready?]
(when ready?
(remove-watch state/db-worker-ready? ::update-page-label)
(update-page-label! (state/get-route-match)))))))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 PDF viewer label resolves before graph restoration

On reload, update-page-label! retries when the worker starts, before the graph opens. The title lookup returns Logseq, and the removed watch never retries, leaving the PDF viewer layout broken.

Learn more

The worker readiness atom tracks whether *db-worker holds a function, not whether a graph connection exists. start-db-worker! installs that function before the app opens its graph. get-route-title returns nil until the graph connection exists, so format-page-route-title falls back to Logseq. The one-time watch is already gone when restore-graph! finishes, and that restore path does not update the page label.

Example: Reload on a PDF page with a saved current graph. Worker readiness flips to true before create-or-open-db finishes; body[data-page] becomes Logseq rather than the PDF page title and stays there until another navigation.

Recommended fix: Trigger update-page-label! after the current graph is restored, or wait for a graph-ready signal before resolving the route title. Recheck the current route at that point.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

(do
(log-fixes! fix-datoms)
(recur (validate-db-result @conn)
(into fixed-entity-ids (map :e) fix-datoms)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Repair count includes valid reference owners

When a repaired block has references, fixed-entity-ids includes valid blocks stamped by the transaction pipeline. The repair notification counts those blocks as invalid blocks it fixed.

Learn more

fix-invalid-blocks! returns every datom in the committed report, not just its requested repairs. transact-pipeline adds :block/tx-id datoms for changed blocks and for blocks referencing changed entities. Mapping :e over that full report includes these unrelated reference owners.

Example: An invalid block B has a missing UUID and a valid block A references B. Repairing B stamps A's revision as well; the notification can say two invalid blocks were fixed when only B was invalid.

Recommended fix: Track IDs of entities selected for repairs from the validation errors or original repair transaction, separately from pipeline-generated datoms. Exclude revision-only and reference-owner changes from the invalid-block count.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +346 to +349
[(str (if (seq fixed-entity-ids)
(str "Validation fixed " (count fixed-entity-ids) " invalid block(s). Your graph is valid now! ")
"Your graph is valid! ")
counts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Graph repair notice ignores user locale

After a successful repair, validate-db broadcasts an English-only message to users in every locale. The new notification bypasses the translation helper and fixes pluralization to block(s).

Learn more

This notification is shipped UI text. The repository's i18n rules require translated messages and locale-specific pluralization, even though the message originates in a worker. Existing translation keys for graph validation live in src/resources/dicts/en.edn; the new repaired-graph message needs its own complete translation entry and a way to select the current locale before broadcasting.

Example: A user viewing the app in Simplified Chinese repairs one invalid block; the success toast says Validation fixed 1 invalid block(s). Your graph is valid now! in English.

Recommended fix: Add a complete repaired-graph message to the translation dictionaries and format the dynamic count through the frontend i18n helper, or pass a translation key and count to the client for formatting. Preserve locale-specific plural handling.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

route.cljs:266 (label resolved before the graph is open). You were right. The db-worker-ready? watch fires as soon as *db-worker is installed, which on a reload is before restore-and-setup! has opened the graph, so get-route-title returned nil and the title became Logseq. Fixed in 05d8514: update-page-label! now waits until the worker is up and :db/restoring? has been cleared (the flag the app sets around graph restore and that the header, sidebar and container already wait on), then labels the current route. The flag is exposed as a watchable atom, frontend.flows/db-restoring?. The new test page-label-waits-for-the-graph-to-be-restored-test has the worker answer without a title until the graph is open and checks body[data-page] ends up as the page title; without the fix it stays Logseq.

validate.cljs:303 (count included pipeline-stamped blocks). You were right. fix-invalid-blocks! returned every datom of the committed report, including the :block/tx-id datoms the pipeline puts on blocks that reference a repaired one. Fixed in e84f5c1: it now returns the entity ids its repair tx-data asked to change (resolved before the transaction, so retracted entities still count), and :fixed-entity-ids is built from those. The committed datoms are still logged and still end the loop when a repair changes nothing. The new test validate-db-reports-only-the-blocks-it-targeted repairs a block without a uuid that a valid block references; without the fix :fixed-entity-ids was [192 193] instead of [192].

validate.cljs:349 (English-only notification). You were right. Fixed in 106161c: the worker now broadcasts :graph.validation/fixed-invalid-blocks with the count and the graph counts as :i18n-args, the payload shape handler/worker.cljs already translates on the client for other worker notifications (e.g. :storage/invalid-data-writing). The en.edn entry is function-valued, so "block"/"blocks" pluralizes and a locale can supply its own rule. Following the repo's dictionary rules (docs/dev-practices.md), I did not add untranslated copies to the other dicts; they fall back to English until someone translates them. bb lang:validate-translations, bb lang:format-dicts and bb lang:lint-hardcoded pass. validate-db-reports-the-blocks-it-repaired now checks the key, the count and the rendered English text for 1 and 2 blocks. One thing left as it was: the neighbouring "Your graph is valid!" and "Validation detected N invalid block(s)" notifications in the same function are still English strings on this branch, although :graph.validation/valid and :graph.validation/invalid-blocks-detected exist in the dicts. That predates these changes and is outside what this PR changes.

yuxi-liu-wired pushed a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 1, 2026
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 2, 2026
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 4, 2026
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/dbtest-last branch 8 times, most recently from 5a067d5 to 1548d7b Compare November 18, 2026 14:39
…ng assets:// URLs

An inline image whose target is a file:// URL with %20 for spaces, such as ![x](file:///tmp/path%20spaces/qa%20image.png), showed a broken image on Electron, while the same file with literal spaces rendered.

mldoc parses the target as a file link whose path keeps the percent-escapes. string-of-url returned that path as is, and the image code treats it as a native path and encodes it again for the assets:// URL, so the file was looked up as path%2520spaces.

string-of-url now decodes the path of a file link, so the native path has real spaces and the assets:// URL is encoded once. A malformed escape such as a lone % is left as written.

Test: string-of-url-decodes-file-url-path-test checks the decoded path, that file-path->assets-url then yields a single-encoded URL, and that literal spaces and a lone % still work.

Fixes logseq/db-test#1386
…of-a-tag

Typing #ET for a tag "Example Tag" that has the alias ET offered "Convert ET to tag" first and did not offer Example Tag. Choosing it turned ET into a separate tag and tagged the block #ET, so the block was missing from Example Tag's table and queries.

Three things combined. search-pages decides whether to offer Convert from :block/alias-source-page-class?, but <get-block never returns that key, so the check never fired. tag-on-chosen-handler converted the page before it resolved the alias source, so the fallback that swaps in the aliased tag no longer applied afterwards. And get-all-classes sent each class's aliases as {:db/id} only (a nested entity is serialized with the attributes read so far), so get-matched-classes had no alias title to match #ET against.

search-pages now asks the worker for the alias source of the typed page and does not offer Convert when it is a tag. tag-on-chosen-handler skips the conversion for an alias of a tag, so the existing swap tags the block with the real tag. get-all-classes sends the uuid and title of each alias.

Tests: tag-search-does-not-convert-class-aliases now uses the real <get-block shape (no alias flag) and the alias-source lookup; hashtag-convert-page-to-tag-skips-alias-of-a-tag-test covers the handler; get-all-classes-sends-alias-titles-for-tag-completion round-trips the thread API result through transit.

Fixes logseq/db-test#1450
Running validation with fix on (the default) repaired invalid blocks, in some cases retracting attributes or deleting entities, and then reported "Your graph is valid!" with :errors nil. Nothing said that data had been changed, and only the validation errors were logged, not the repairs.

validate-and-fix-invalid-blocks! loops fix-invalid-blocks! until nothing is left to fix and returns only the last round's validation result, which is clean by then.

Each round's applied fix is now logged at :debug next to the validation errors. The result carries :fixed-entity-ids, the entities the repairs touched, and when there are any the notification says "Validation fixed N invalid block(s)" instead of "Your graph is valid!".

Test: validate-db-reports-the-blocks-it-repaired repairs a block that lacks a uuid and checks the result ids, the notification text, and that a second run reports nothing.

Fixes logseq/db-test#1067
…r lays out after a reload

After reloading a page that contains a PDF, opening the PDF showed an empty pane with the toolbar over the app header, and the PDF page was invisible. Navigating to another page and back fixed it.

The PDF viewer layout in pdf.css only applies under body[data-page]. update-page-label! sets that attribute from the route title, which it reads through the db-worker. On a reload the first route match runs before the db-worker exists, the call throws, and nothing sets the attribute again until the next navigation.

update-page-label! now waits for the db-worker when it is not ready and labels the current route as soon as it is.

Test: page-label-is-set-once-db-worker-is-ready-test.

Fixes logseq/db-test#1384
…orker starts

After reloading a page that contains a PDF, the PDF viewer could still lay out wrongly: body[data-page] was set to "Logseq" instead of the page title, and nothing corrected it until the next navigation.

Cause: the previous fix retried update-page-label! when state/db-worker-ready? turned true. On a reload the db-worker is installed before the current graph is restored, so the retry ran while :thread-api/get-route-title still had no graph connection and returned nil, which format-page-route-title turns into "Logseq". The watch was already removed, so nothing retried.

update-page-label! now waits until the db-worker is up and :db/restoring? has been cleared (the signal the app uses for "graph restored", set by restore-and-setup! and start!), then labels the current route. frontend.flows/db-restoring? exposes that state key as a watchable atom.

Test: page-label-waits-for-the-graph-to-be-restored-test makes the db-worker answer without a title until the graph is open, and checks that body[data-page] is the page title once restoring ends.

Fixes logseq/db-test#1384
…ocks the pipeline stamped

After "Validate graph" repaired an invalid block that other blocks reference, the notification said it had fixed more invalid blocks than there were: "Validation fixed 2 invalid block(s)" for one invalid block and one valid block that references it.

Cause: fix-invalid-blocks! returned every datom of the committed tx-report, and validate-and-fix-invalid-blocks! collected the entity ids of those datoms. The transact pipeline adds :block/tx-id datoms for changed blocks and for the blocks that reference them, so valid reference owners were counted as repaired.

fix-invalid-blocks! now returns the entities its repair tx-data asks to change (resolved before the transaction, so retracted entities are kept) along with the committed datoms, which are still logged and still end the loop when a repair changes nothing. :fixed-entity-ids is built from those ids.

Test: validate-db-reports-only-the-blocks-it-targeted repairs a block without a uuid that a valid block references, and checks that only the repaired block is in :fixed-entity-ids and counted in the notification, while the referencing block was stamped by the pipeline.

Fixes logseq/db-test#1067
…fication

After "Validate graph" repaired blocks, the success toast was English whatever language the app was set to, and always said "block(s)".

Cause: validate-db built the text in the worker with str and broadcast it as a plain string, bypassing the client's translation helper.

The worker now broadcasts the i18n key :graph.validation/fixed-invalid-blocks with the count and the graph counts as arguments, the same way the other worker notifications (e.g. :storage/invalid-data-writing) do, and the client formats it in the user's locale. The English entry in en.edn is a function-valued translation, so it pluralizes "block"/"blocks" and other locales can supply their own plural rules; other locales fall back to English until they are translated.

Test: validate-db-reports-the-blocks-it-repaired now checks the notification key and count, and the rendered English text for 1 and 2 blocks.

Fixes logseq/db-test#1067
CI's typos check reads every changed file, and this branch changes en.edn.
…ce, so it merges cleanly with logseq#13893

The test this PR added to worker/handler/property_test.cljs sat at the same place as the ones logseq#13893 adds there, so the two PRs conflicted and the nightly merge left one of them out. The test is unchanged; it now lives in frontend.worker.handler.property-tag-completion-test, which carries the requires it needs, and property_test.cljs is back to master's.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant