Skip to content

refactor(blog): dedupe the 'string-or-JSON.stringify' block field shape - #6986

Closed
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/blog-block-registry-json-str-dedupe-w2
Closed

refactor(blog): dedupe the 'string-or-JSON.stringify' block field shape#6986
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/blog-block-registry-json-str-dedupe-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Source: reduction found while auditing apps/web/src/components/sandbox/content/blog/ (blog sandbox UI area) for dead code/duplication, per the ship-it checklist's dedup guidance.

What: BlockEditor in blocks/block-registry.tsx repeated the identical ternary — "if this block field is already a JSON string, pass it through, otherwise JSON.stringify it (defaulting to [])" — three times (CardGroup's cards, Table's headers, Table's rows). Extracted the one-line jsonStr() helper (matching the existing local str() helper's style/placement in this file) and replaced all three call sites.

Why a maintainer wants it: removes copy-pasted logic that would otherwise need three edits if the field-normalization rule ever changes (e.g. a null vs [] default), with zero behavior change.

Net delta: -15 / +8 lines, purely mechanical — same runtime behavior (verified by reading: jsonStr(v) is byte-identical to each removed ternary).

Reviewer check: cd apps/web && bunx tsc --noEmit -p . (no new errors from this file) and bunx oxlint src/components/sandbox/content/blog/blocks/block-registry.tsx (0 warnings/errors).

Locally verified: bun run fmt, bunx oxlint on the changed file, and a scoped tsc --noEmit in apps/web (no errors touching this file). No existing test covers this file's render branches, so nothing to invert; full CI validates the rest.


Summary by cubic

Extracts the repeated string-or-JSON.stringify block field normalization logic in BlockEditor into a single jsonStr() helper, removing three copies of the same ternary. Behavior is unchanged; future changes to the default (e.g., null vs []) become a one-line edit.

Written for commit 55c49ee. Summary will update on new commits.

Review in cubic

@pedrofrxncx

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR sat past the bot's 48h merge window, main has moved on, and its CI results no longer reflect the current base. This is a housekeeping close, not a rejection of the change — if the underlying problem still exists, the bot will find it again and open a fresh, rebased PR.

[studio-bot:stale-close]

@pedrofrxncx pedrofrxncx closed this Sep 8, 2026
@pedrofrxncx
pedrofrxncx deleted the refactor/blog-block-registry-json-str-dedupe-w2 branch September 8, 2026 16:13
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.

1 participant