Skip to content

Fix forms embed definition envelope handling - #983

Merged
ascorbic merged 1 commit into
emdash-cms:mainfrom
ppppangu:fix-forms-embed-definition-envelope
May 11, 2026
Merged

ascorbic merged 1 commit into
emdash-cms:mainfrom
ppppangu:fix-forms-embed-definition-envelope

Conversation

@ppppangu

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes embedded forms rendered by @emdash-cms/plugin-forms so the Astro block component reads the standard plugin API success envelope.

The public form definition route is exposed through the core plugin API route, which returns successful responses as { data: ... }. FormEmbed.astro previously treated the whole JSON body as the form definition, so form.status was undefined and the form silently did not render.

This PR moves public definition response handling into a small forms-owned parser that reuses emdash/plugin-utils' existing parseApiResponse() envelope unwrapping, then uses that parser from the Astro embed component.

No related issue.

Type of change

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

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: GPT-5 Codex

Screenshots / test output

Validated locally on Windows:

  • pnpm build passes
  • pnpm typecheck passes
  • pnpm lint passes with 0 errors
  • pnpm --filter @emdash-cms/plugin-forms test passes
  • pnpm --filter @emdash-cms/plugin-forms typecheck passes
  • Targeted Prettier write/check for changed files passes
  • git diff --check passes

Notes:

  • CI=true pnpm test:unit currently fails locally on Windows before the forms test run because @emdash-cms/marketplace's publish-e2e.test.ts invokes the built CLI and hits Node's ESM loader error for a d: absolute Windows path. This appears unrelated to this forms change.
  • Full pnpm format:check reports repo-wide formatting issues on Windows, while targeted Prettier checks for this PR's changed files pass.

@changeset-bot

changeset-bot Bot commented May 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 16cc134

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

This PR includes changesets to release 3 packages
Name Type
@emdash-cms/plugin-forms Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site 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

@github-actions

github-actions Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ppppangu

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 11, 2026
@ascorbic
ascorbic requested a review from Copilot May 11, 2026 06:03
@ascorbic

Copy link
Copy Markdown
Member

/review

@ask-bonk

ask-bonk Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Good. The test:unit modification is consistent with other plugin tests.

Now let me do a quick sanity check — does parseApiResponse correctly handle the test case { data: undefined }? When you JSON.stringify({ data: undefined }), the result is "{}", so body.data is undefined. The check if (!form || form.status !== "active") returns null. Test passes ✓.

But there's a subtle issue: what if the API does not return the envelope (e.g., during migration or future changes)? The new code would silently return null without logging. The old code would have had form.status be undefined and silently fail too. Same UX — not a regression but maybe worth a console.warn. Minor.

Overall this is a small, focused, well-tested bugfix:

  • The change correctly identifies and fixes the envelope bug
  • A separate testable parser module is extracted
  • Tests cover the main paths (envelope, missing data, paused, error response)
  • Types are reused from types.ts properly
  • Changeset is correct and properly scoped
  • Pre-existing risks (JSON parse failures) are unchanged

The PR is well-scoped, has good test coverage, and correctly fixes a real bug. I'll respond with LGTM.

LGTM!

github run

@pkg-pr-new

pkg-pr-new Bot commented May 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

emdash

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

create-emdash

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

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

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 16cc134

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

This PR fixes embedded forms rendered by @emdash-cms/plugin-forms by correctly unwrapping the core plugin API success envelope ({ data: ... }) when fetching public form definitions from the Astro embed component.

Changes:

  • Added a small forms-owned response parser (parsePublicFormDefinitionResponse) that reuses emdash/plugin-utils’ parseApiResponse() to unwrap { data: ... }.
  • Updated FormEmbed.astro to use the new parser (and removed the incorrect “treat entire JSON body as the definition” behavior).
  • Added Vitest coverage for the new parsing behavior and wired the forms plugin into workspace unit tests.

Reviewed changes

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

Show a summary per file
File Description
packages/plugins/forms/src/astro/FormEmbed.astro Uses the new parser so embeds read the { data: ... } envelope correctly.
packages/plugins/forms/src/public-definition.ts Introduces a focused parser for public definition responses, including active-form filtering.
packages/plugins/forms/tests/public-definition.test.ts Adds unit tests validating envelope unwrapping and null behavior for inactive/missing/failed cases.
packages/plugins/forms/vitest.config.ts Adds Vitest config consistent with other plugins’ test setups.
packages/plugins/forms/package.json Adds vitest devDependency and a test script for the forms plugin package.
package.json Includes @emdash-cms/plugin-forms in the test:unit filter set.
.changeset/forms-embed-definition-envelope.md Adds a patch changeset describing the user-visible bug fix.
pnpm-lock.yaml Lockfile update to reflect the new vitest devDependency for the forms plugin.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

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

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@ascorbic
ascorbic enabled auto-merge (squash) May 11, 2026 06:16
@ascorbic
ascorbic merged commit 06d5f3f into emdash-cms:main May 11, 2026
33 of 34 checks passed
@emdashbot emdashbot Bot mentioned this pull request May 11, 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