fix(embed-sdk): resolve API host for widgets nested in user-menu modal#14
Merged
Conversation
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>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Widgets (
next-profile,next-my-invoices) rendered insidenext-user-menu's "My Account" modal inherited an emptyapi-host, so theirfetch()calls resolved against the page origin. In Vite dev (localhost:5173) this returned the SPAindex.htmlfallback, and the widgets failed parsing<!DOCTYPE html>as JSON:Changes
demo-profile.html/demo-my-invoices.html: addapi-host="__API_HOST__"to<next-user-menu>(substituted tolocalhost:3000by the Vitedemo-env-replaceplugin), matching the existingdemo-user-menu.html.base-widget.tsdetectApiHostFromScript(): fall back to a sibling widget'sapi-hostwhen no loader host (__nextEmbedApiHost) ornext-embedscript tag is present (Vite dev module import). Mirrorsindex.tsdetectApiHost()step 4 so a widget with a missingapi-hostdegrades gracefully instead of silently fetching the wrong origin.Testing
pnpm build:sdkpasses (tsc + vite).🤖 Generated with Claude Code