Skip to content

fix(embed-sdk): resolve API host for widgets nested in user-menu modal#14

Merged
chriskehayias merged 1 commit into
mainfrom
dev
May 31, 2026
Merged

fix(embed-sdk): resolve API host for widgets nested in user-menu modal#14
chriskehayias merged 1 commit into
mainfrom
dev

Conversation

@chriskehayias
Copy link
Copy Markdown
Contributor

Summary

Widgets (next-profile, next-my-invoices) rendered inside next-user-menu's "My Account" modal inherited an empty api-host, so their fetch() calls resolved against the page origin. In Vite dev (localhost:5173) this returned the SPA index.html fallback, and the widgets failed parsing <!DOCTYPE html> as JSON:

Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Changes

  • demo-profile.html / demo-my-invoices.html: add api-host="__API_HOST__" to <next-user-menu> (substituted to localhost:3000 by the Vite demo-env-replace plugin), matching the existing demo-user-menu.html.
  • base-widget.ts detectApiHostFromScript(): fall back to a sibling widget's api-host when no loader host (__nextEmbedApiHost) or next-embed script tag is present (Vite dev module import). Mirrors index.ts detectApiHost() step 4 so a widget with a missing api-host degrades gracefully instead of silently fetching the wrong origin.

Testing

  • pnpm build:sdk passes (tsc + vite).
  • Profile/Invoices tabs in the user-menu modal now load against the Next.js API instead of erroring.

🤖 Generated with Claude Code

The profile/invoices widgets rendered inside next-user-menu's "My Account"
modal inherited an empty api-host, so their fetches resolved against the
page origin (Vite dev: localhost:5173). Vite returned its index.html
fallback and the widgets choked parsing `<!DOCTYPE html>` as JSON
("Unexpected token '<' ... is not valid JSON").

- demo-profile.html / demo-my-invoices.html: add api-host="__API_HOST__"
  to <next-user-menu> (substituted to localhost:3000 by the Vite
  demo-env-replace plugin), matching demo-user-menu.html.
- base-widget.ts detectApiHostFromScript(): fall back to a sibling
  widget's api-host when no loader host or next-embed script tag is
  present (Vite dev module import), mirroring index.ts detectApiHost()
  step 4. A widget with a missing api-host now degrades gracefully
  instead of silently fetching the wrong origin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chriskehayias chriskehayias merged commit 40bc04e into main May 31, 2026
1 check passed
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/embed-sdk/src/shared/base-widget.ts 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants