Skip to content

fix(admin): initialize plugin block fields from initial values#184

Merged
ascorbic merged 1 commit into
emdash-cms:mainfrom
masonjames:codex/portabletext-plugin-block-defaults
Apr 27, 2026
Merged

fix(admin): initialize plugin block fields from initial values#184
ascorbic merged 1 commit into
emdash-cms:mainfrom
masonjames:codex/portabletext-plugin-block-defaults

Conversation

@masonjames

@masonjames masonjames commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes plugin block defaults so initial_value seeds a new admin plugin block once.

When editing, existing saved values win over defaults, including explicit falsy values like 0, false, and "", so defaults do not reapply over existing block data.

While rebasing onto current main, this also includes narrow lint/type-safety cleanup needed for the full lint suite to return 0 diagnostics.

Type of change

  • Bug fix
  • Feature (requires approved Discussion)
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm --silent lint:json | jq '.diagnostics | length' returns 0
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code

Screenshots / test output

  • pnpm format
  • pnpm --silent lint:quick
  • pnpm --filter @emdash-cms/admin exec vitest run tests/editor/PortableTextEditor.test.tsx
  • pnpm typecheck
  • pnpm --silent lint:json | jq '.diagnostics | length'0

@changeset-bot

changeset-bot Bot commented Apr 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2f99407

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Apr 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@184

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@184

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@184

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@184

emdash

npm i https://pkg.pr.new/emdash@184

create-emdash

npm i https://pkg.pr.new/create-emdash@184

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@184

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@184

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@184

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@184

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@184

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@184

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@184

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@184

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@184

commit: 2f99407

@masonjames

Copy link
Copy Markdown
Contributor Author

Rebased this onto current main and tightened the scope/wording.

The bug still applies on main: the admin plugin-block modal was initializing from existing values or {}, so field.initial_value never seeded new plugin blocks. This now seeds defaults once for new blocks and lets saved values win when editing, including explicit falsy values like 0, false, and "".

I also included narrow lint/type-safety cleanup from the rebase so full lint is clean locally.

Verified locally:

  • pnpm format
  • pnpm --silent lint:quick
  • pnpm --filter @emdash-cms/admin exec vitest run tests/editor/PortableTextEditor.test.tsx — 49 passed
  • pnpm typecheck
  • pnpm --silent lint:json | jq '.diagnostics | length'0

@masonjames masonjames marked this pull request as ready for review April 13, 2026 14:57
Copilot AI review requested due to automatic review settings April 13, 2026 14:57

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

Fixes how admin “plugin blocks” initialize their form state so initial_value defaults seed a newly-inserted block once, while existing saved values (including falsy values like 0, false, and "") take precedence during edits. The PR also includes small type-safety/lint cleanups required to keep the full lint suite at 0 diagnostics and adds targeted unit tests around the new behavior.

Changes:

  • Seed plugin block modal form state from Block Kit field initial_value defaults, merging existing saved values over defaults (preserving explicit falsy values).
  • Add unit tests for plugin block defaulting/merge behavior.
  • Tighten a few spots across core tooling/runtime/routes to improve type-safety (e.g., safer JSON parsing, record guards, removal of unnecessary non-null assertions).

Reviewed changes

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

Show a summary per file
File Description
packages/core/tsdown.config.ts Reads package version with runtime validation instead of a direct asserted parse.
packages/core/src/storage/s3.ts Refactors S3Client config construction for clearer typing/lint behavior.
packages/core/src/query.ts Removes unnecessary non-null assertion when preview mode is already guarded.
packages/core/src/emdash-runtime.ts Adds safer parsing for stored JSON string arrays (filters to strings).
packages/core/src/astro/routes/api/content/[collection]/index.ts Introduces an isRecord guard to simplify/strengthen response-shape checks.
packages/core/src/astro/integration/vite-config.ts Removes non-null assertions by relying on useSource/adminSourcePath narrowing.
packages/core/src/api/handlers/redirects.ts Removes a non-null assertion in loop formatting.
packages/admin/vitest.config.ts Simplifies plugin typing (removes an explicit cast).
packages/admin/tests/editor/PortableTextEditor.test.tsx Adds tests covering plugin block default seeding and edit-mode merging semantics.
packages/admin/src/components/PortableTextEditor.tsx Implements default extraction/merge helpers and uses them in the plugin block modal.
lunaria.config.ts Makes Lunaria locale tuple construction type-safe with a non-empty helper.
.changeset/late-kids-visit.md Adds a patch changeset documenting the admin fix.

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

@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@masonjames masonjames force-pushed the codex/portabletext-plugin-block-defaults branch from 7faa110 to 2f99407 Compare April 14, 2026 15:16
@github-actions github-actions Bot added size/M and removed size/L labels Apr 14, 2026
@masonjames

Copy link
Copy Markdown
Contributor Author

Narrowed this to the plugin-block initial_value fix, tests, and changeset.

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ascorbic ascorbic merged commit 4c9f04d into emdash-cms:main Apr 27, 2026
27 checks passed
@emdashbot emdashbot Bot mentioned this pull request Apr 27, 2026
0aveRyan pushed a commit to 0aveRyan/emdash that referenced this pull request Apr 27, 2026
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.

3 participants