Skip to content

fix: return stable block clientId values for unchanged content - #528

Merged
josephfusco merged 3 commits into
mainfrom
fix/deterministic-client-id
Oct 22, 2026
Merged

josephfusco merged 3 commits into
mainfrom
fix/deterministic-client-id

Conversation

@josephfusco

Copy link
Copy Markdown
Member

Fixes #505.

Every block's clientId came from uniqid(), so the same query against unchanged content returned different IDs on every request. That breaks response caching, static regeneration diffs, and React keys built from clientId / parentClientId.

clientId is now a hash of:

  • the post's database ID, so the same content in two posts gets different IDs
  • the block's position: its parent's clientId plus its index
  • the block's own name, attributes, and innerHTML

It stays the same until that block changes, and it keeps the 13-character hex format uniqid() produced. Blocks pulled in from elsewhere (reusable blocks, template parts, post content) are seeded with the parent block's ID, so a reusable block used twice still gets unique IDs.

Blocks returned through wpgraphql_content_blocks_pre_resolve_blocks without a clientId fall back to a hash of the block alone. Before, they got a random ID. In that path, identical sibling blocks will share an ID, so filters that build their own block lists should set clientId themselves.

Testing

  • New test: IDs match across two requests, are unique within a post (including identical siblings and a reusable block used twice), differ between two posts with the same content, and every parentClientId points at a block in the response. Editing one block changes only that block's ID. It fails on main and passes with this change.
  • Full suite passes locally (WordPress 6.9, PHP 8.3, 96 tests), along with phpcs and phpstan.
Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Assisting with reproducing the bug, the fix, and the test.

@josephfusco
josephfusco requested review from a team and colinmurphy as code owners October 22, 2026 15:00
@github-actions

Copy link
Copy Markdown
Contributor

🛝 WordPress Playground

Built from 242cb68

Launch WordPress Playground

Opens GraphiQL with WPGraphQL and this build active. The "Content Blocks Demo" post has core blocks to query through editorBlocks.

@josephfusco
josephfusco merged commit 1c2dcfe into main Oct 22, 2026
15 checks passed
@josephfusco
josephfusco deleted the fix/deterministic-client-id branch October 22, 2026 19:46
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.

Random clientId (uniqid()) makes responses for unchanged content non-deterministic

1 participant