Skip to content

fix: sanitize get-blocks worker results#12884

Open
megayu wants to merge 1 commit into
masterfrom
fix/get-blocks-nil-sanitize
Open

fix: sanitize get-blocks worker results#12884
megayu wants to merge 1 commit into
masterfrom
fix/get-blocks-nil-sanitize

Conversation

@megayu

@megayu megayu commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

This partially addresses logseq/db-test#974.

The issue reports a blank page caused by Cannot store nil as a value when rendering a page that contains a malformed block. The reported entity had :block/page set but :block/parent nil. That data shape is invalid for a block, and DataScript rejects re-transacting a map that contains nil-valued attributes.

This change does not try to identify or fix the original source of the malformed data. Instead, it hardens the worker :thread-api/get-blocks response boundary by removing nil-valued entries from returned :block and :children maps before they are serialized back to the renderer. This prevents lazy-loaded/query/table block results from carrying maps such as {:block/parent nil} into renderer-side d/transact!.

Existing graph repair remains the responsibility of graph validation, for example logseq graph validate --graph <graph> --fix, which already has logic to repair blocks that have :block/page but no :block/parent.

Copilot AI 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.

Pull request overview

Hardens the db worker’s :thread-api/get-blocks boundary by sanitizing block payloads returned to the renderer, preventing d/transact! failures caused by nil-valued attributes in malformed block maps.

Changes:

  • Added sanitize-block-result to strip nil-valued entries from :block and each map in :children before Transit serialization.
  • Applied sanitization to the get-blocks-with-cache path so cached responses are also cleaned.
  • Added a unit test ensuring nil-valued keys are removed from both the parent block and children blocks in the worker response.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/main/frontend/worker/db_core.cljs Sanitizes :thread-api/get-blocks results to avoid returning nil-valued attributes to the renderer.
src/test/frontend/worker/db_core_test.cljs Adds coverage asserting nil-valued keys are removed from returned :block and :children maps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@megayu megayu requested a review from tiensonqin July 8, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants