Skip to content

fix(api): reject BlockNote block types the web editor cannot render - #838

Merged
pikann merged 1 commit into
Paca-AI:masterfrom
kayahk:fix/blocknote-block-type-validation
Nov 30, 2026
Merged

pikann merged 1 commit into
Paca-AI:masterfrom
kayahk:fix/blocknote-block-type-validation

Conversation

@kayahk

@kayahk kayahk commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #837.

What

The API accepted any block type in BlockNote content, and never looked inside nested children. A single comment carrying {"type":"p"} (an HTML tag name) therefore took a whole task view down in the web app:

undefined is not an object (evaluating 't.nodes[e.type].isInGroup')

@blocknote/core resolves every block type against the editor schema while rendering, so the miss is fatal for the view, not just for that one block. The same record also broke server-side rendering (get_task: Cannot read properties of undefined (reading 'propSchema')).

Change

  • New internal/pkg/blocknote: the block types the editor renders — BlockNote 0.48 defaultBlockSpecs plus the app's custom blocks from apps/web/src/components/shared/blocknote-schema.tsx (mermaid, annotationCard) — and Validate, which walks nested children and reports the offending index and type.
  • dto.ValidateBlockNoteContent (task description create/update, document content create/update) now delegates to it. Array-shape errors keep their existing message.
  • activity.IsCommentContentValid (task comments and document comments, add and update) applies the same check to the block-array path. The legacy {"text": "…"} shape and all existing error codes are unchanged.
  • Fixture teamMentionContent in internal/service/task/activity_service_test.go built a block with no type at all — the same defect in test form; it now uses paragraph.

Rejection surfaces as 400 ACTIVITY_COMMENT_CONTENT_INVALID for comments and the existing 400 for description/document writes, so an agent that wrote the bad payload can see what it did wrong.

Tests

  • internal/pkg/blocknote: all renderable types (including nested children, mermaid, annotationCard, table) accepted; unknown top-level type, unknown nested type and missing type rejected.
  • dto: unknown top-level and nested block types rejected, existing cases unchanged.
  • activity service: p block and nested p child rejected with the kind's invalid-content error.
  • HTTP integration: POST .../activities/comments with {"type":"p"} and with a nested p child → 400 + ACTIVITY_COMMENT_CONTENT_INVALID.

Sabotage proof (each behaviour stubbed separately, restored after):

--- FAIL: TestValidate_RejectsUnknownType            expected an unknown block type to be rejected
--- FAIL: TestValidate_RejectsUnknownNestedChildType expected an unknown nested block type to be rejected
--- FAIL: TestValidateBlockNoteContent_RejectsUnknownBlockType        expected a block with an unknown type to be rejected
--- FAIL: TestValidateBlockNoteContent_RejectsUnknownNestedBlockType  expected a nested block with an unknown type to be rejected
--- FAIL: TestAddComment_InvalidContent  content "[{\"type\":\"p\",...}]": expected the kind's invalid-content error, got <nil>
--- FAIL: TestActivities_AddComment_UnknownBlockTypeReturns400  html tag as block type: expected 400, got 201: {... "content":[{"content":[{"text":"hi","type":"text"}],"type":"p"}], ...}

Gates, all inside services/api on this commit: go build ./..., go vet ./..., golangci-lint run --timeout=5m (0 issues), go test -race $(go list ./... | grep -v '/test/e2e'), git diff --check. The PACA_E2E suite was not run (needs the cluster-backed harness).

Not covered

  • Unknown inline content types (teamMention, taskReference, docReference, …): the reported crash is block-type-only, and a false rejection there would break mention writes.
  • Pre-existing rows already carrying an unknown type are not migrated. They stay as broken as they are, but an edit that re-saves them now fails loudly instead of silently re-storing the bad block — repairing such a record is a data fix (rewrite the block type, keep the block ids).
  • The type list is a snapshot: a BlockNote upgrade that adds a block type, or a new custom block, needs it extended. The web schema file is the source to diff against, and internal/pkg/blocknote carries that note next to the list.

A comment carrying a block type outside the editor's schema (an HTML tag
name such as "p" instead of "paragraph") is stored and then crashes the
whole task view on render — `t.nodes[e.type].isInGroup` on an undefined
node type — and the server-side get_task path dies on the same record
with `propSchema` of undefined. Nothing validated the type, and nested
children were not inspected at all.

Add internal/pkg/blocknote with the block types the editor can render
(BlockNote 0.48 defaultBlockSpecs plus the custom mermaid and
annotationCard blocks) and a validator that walks nested children. Route
task descriptions and document content (dto.ValidateBlockNoteContent)
and task/document comments (activity.IsCommentContentValid) through it,
so the write fails with 400 / ACTIVITY_COMMENT_CONTENT_INVALID instead of
storing content nobody can open.

Refs Paca-AI#837

@pullfrog pullfrog 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.

ℹ️ No critical issues — one minor suggestion inline, plus an inline-content follow-up.

Approach: sound — one allow-list plus a recursive validator, wired into both places that persist BlockNote documents (dto.ValidateBlockNoteContent for task descriptions and document content, activity.IsCommentContentValid for task/doc comments), so every writer goes through the same check.

Reviewed changes

  • New internal/pkg/blocknote — Types (the 16 renderable block types) and Validate, which walks nested children and reports the index and type of the offending block. I diffed the list against the pinned @blocknote/[email protected] source and apps/web/src/components/shared/blocknote-schema.tsx; it matches exactly, and customSchema is the only editor schema the web uses.
  • dto.ValidateBlockNoteContent now delegates to it; absent/null handling and the array-shape error message are unchanged.
  • activity.IsCommentContentValid validates the block-array path while leaving the legacy {"text": …} shape alone.
  • Tests cover unknown top-level and nested types, the missing-type case, and a 400 ACTIVITY_COMMENT_CONTENT_INVALID over HTTP; the teamMentionContent fixture now sets type: "paragraph".

Verified locally: the blocknote, dto and activity packages and go test ./test/integration -run TestActivities_AddComment pass; go vet is clean.

ℹ️ Unknown inline content types still crash the same way

Validate inspects only a block's type and children, so a payload with a bogus inline type — [{"type":"paragraph","content":[{"type":"p","text":"hi"}]}] — is still stored and still takes the view down: BlockNote converts inline content on the same load path through blockOrInlineContentToContentNode, which throws node type p not found in schema. The issue defers this because a false rejection "would break mention writes", but a type-only allow-list (text, link, teamMention, taskReference, docReference) cannot reject a mention — only prop validation could. Worth a follow-up.

Technical details
# Unknown inline content types remain unvalidated

## Affected sites
- `services/api/internal/pkg/blocknote/blocknote.go:50` — `validateBlocks` reads `type` and `children` only; block `content` (inline nodes) and table cells (`content.rows[].cells[].content`) are never inspected.
- `apps/web/src/components/shared/blocknote-schema.tsx` — the editor inline schema is `defaultInlineContentSpecs` (`text`, `link`) plus `teamMention`, `taskReference`, `docReference`.

## Required outcome
- Inline content the editor cannot render is rejected on write (or normalised on read), so one bad inline node cannot crash the task or document view.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

var arr []json.RawMessage
if json.Unmarshal([]byte(trimmed), &arr) == nil {
return true
return blocknote.Validate(content) == nil

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.

Suggested change
return blocknote.Validate(content) == nil
if err := blocknote.Validate(content); err != nil {
return false // TODO: propagate err so the 400 names the index/type
}
return true

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.

Correction: ignore the suggested edit above (it only adds a TODO) — the actual finding is that IsCommentContentValid collapses blocknote.Validate's error to a bool, so a non-empty comment rejected for {"type":"p"} still returns the misleading message activity: comment content must not be empty and loses the index/type promised in the issue's acceptance criteria; propagating a wrapped error from AddComment/UpdateComment/AddSystemComment keeps errors.Is and the 400 code intact while naming the offending block.

Pullfrog  | View workflow run | via Pullfrog | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann 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.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit ad5040f into Paca-AI:master Nov 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api: reject BlockNote block types the web editor cannot render (one bad comment crashes the task view)

2 participants