Repository navigation
fix: file:// image paths, #alias of a tag, Validate graph report, PDF viewer after reload - #13897
yuxi-liu-wired wants to merge 9 commits into
Conversation
| (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))))))))) |
There was a problem hiding this comment.
🟡 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.
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))) |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| [(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) |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
route.cljs:266 (label resolved before the graph is open). You were right. The validate.cljs:303 (count included pipeline-stamped blocks). You were right. validate.cljs:349 (English-only notification). You were right. Fixed in 106161c: the worker now broadcasts |
8a999eb to
f895574
Compare
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
e9e8eb4 to
e19180f
Compare
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
e19180f to
4b1e077
Compare
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
…h report, PDF viewer after reload (squashed: its commits conflicted one by one with the stack)
5a067d5 to
1548d7b
Compare
…ng assets:// URLs An inline image whose target is a file:// URL with %20 for spaces, such as , 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.
1548d7b to
8f869e7
Compare
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
%20in afile://URL (Electron)What the user sees:
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"}]andstring-of-urlreturned the link with its percent-escapes. The image code treats that as a native path andfile-path->assets-urlencodes it again, so the request wasassets:///tmp/path%2520spaces/....Change:
string-of-url(block.cljs) decodes the path of afilelink withcommon-util/safe-decode-uri-component(a malformed escape such as a lone%is left as written). The same fix applies tofile:links that open a file, which got the same%20path.Tests:
frontend.components.block.file-url-test: decoded path, single-encodedassets://URL, literal spaces, lone%.#1450:
#alias-of-a-tagoffers "Convert to tag" and makes a separate tagWhat the user sees: with tag
Example TagaliasedET, typing#EToffersConvert "ET" to tagfirst and notExample Tag. Choosing it makesETa tag of its own and tags the block#ET, so the block is missing fromExample Tag's table and queries.Cause (three parts, all confirmed in the code and by the tests):
search-pagesdecides from:block/alias-source-page-class?, but<get-blocknever returns that key (it is only set for a map with:block/_alias, plain_value.cljs), so the guard never fired.tag-on-chosen-handlerconverted the page before resolving the alias source, so its fallback that swaps in the aliased tag no longer applied afterwards.get-all-classesreturned each class's:block/aliasas{:db/id}only (a nested entity crosses the worker boundary with just the attributes read so far), soget-matched-classeshad no alias title to match#ETagainst.Change:
search-pagesasks 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-handlerskips the conversion for an alias of a tag; the existing swap then tags the block with the real tag.get-all-classessends:db/id,:block/uuidand:block/titlefor each alias.Tests:
tag-search-does-not-convert-class-aliases(editor_test) now uses the real<get-blockshape;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!loopsfix-invalid-blocks!until nothing is left and returns only the last (clean) round.Change: each applied fix is logged at
:debugnext 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-blockswith the count (pluralized inen.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) andvalidate-db-reports-only-the-blocks-it-targeted(a valid block referencing the repaired one is not counted).Not decided here: whether the
:db/retractEntitybranches (e.g. "External URL") should exist at all; that is a maintainer call. The five otherwhen fixpasses 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-workerthrows "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 asfrontend.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 toLogseq.Tests:
page-label-is-set-once-db-worker-is-ready-testandpage-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
pnpm cljs:run-teston the final tree has 0 failures, 0 errors. I used one combined revert instead ofprove-fix.shper file.Not in this PR
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 withvalidate-block-titleafteroutliner-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.#Assettag hidden when "Hide from Node" is off): needs a maintainer's choice.tags-cphidesldb/internal-tagsunconditionally, and:logseq.class/Assetis in that set on purpose ("Built-in classes that are hidden on a node and all pages view"; it is also a private tag).#Assetalso hashide-from-node trueby default, so the toggle is redundant for it today. Honouring the toggle is a one-line change intags-cp(do not treat Asset as an internal tag there), but it changes a documented behaviour.display-propertiesskips the "other position" filter whenpage-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.