fix(admin): initialize plugin block fields from initial values#184
Conversation
🦋 Changeset detectedLatest commit: 2f99407 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
274bed8 to
80fbdaa
Compare
14440fb to
214d2cf
Compare
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
|
Rebased this onto current The bug still applies on main: the admin plugin-block modal was initializing from existing values or I also included narrow lint/type-safety cleanup from the rebase so full lint is clean locally. Verified locally:
|
There was a problem hiding this comment.
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_valuedefaults, 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.
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
7faa110 to
2f99407
Compare
|
Narrowed this to the plugin-block |
What does this PR do?
Fixes plugin block defaults so
initial_valueseeds 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
Checklist
pnpm typecheckpassespnpm --silent lint:json | jq '.diagnostics | length'returns 0pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure
Screenshots / test output
pnpm formatpnpm --silent lint:quickpnpm --filter @emdash-cms/admin exec vitest run tests/editor/PortableTextEditor.test.tsxpnpm typecheckpnpm --silent lint:json | jq '.diagnostics | length'→0