Skip to content

[SITES-35203] fix(host-react): prevent GuestUIFrame crash when guest is undefined - #148

Merged
fe-lix- merged 5 commits into
adobe:mainfrom
valeriat-ens:bug/SITES-35203-undefined-guest-crashes-cfe
Jul 23, 2026
Merged

[SITES-35203] fix(host-react): prevent GuestUIFrame crash when guest is undefined#148
fe-lix- merged 5 commits into
adobe:mainfrom
valeriat-ens:bug/SITES-35203-undefined-guest-crashes-cfe

Conversation

@valeriat-ens

@valeriat-ens valeriat-ens commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Jira

SITES-35203

Summary

  • Guard against a missing host or guest before resolving the frame URL and attaching the UI, so an unavailable guest renders null instead of throwing.
  • Hooks now run unconditionally to satisfy the rules of hooks.
  • Add unit tests for GuestUIFrame and a jest moduleNameMapper to strip the .js extension from relative imports.

Root cause

Reproduction: a local dummy guest extension whose error handler calls guestConnection.host.modal.close() from within a catch block (per the example in the ticket):

const handleClick = React.useCallback(async () => {
  if (!guestConnection) {
    throw new Error("Required data missing");
  }
  setLoading(true);
  try {
    await new Promise((resolve, reject) =>
      setTimeout(() => reject(new Error("Crash!")), 0)
    );
  } catch (error) {
    console.error("Error:", error);
    guestConnection.host.modal.close();
  }
}, [guestConnection]);

Symptom: calling host.modal.close() tears down the modal and removes the guest. On the next host render, GuestUIFrame is evaluated while the guest no longer exists, and the host UI crashes instead of unmounting cleanly.

Analysis: the failure was not in the extension. In GuestUIFrame, host.guests.get(guestId) can return undefined (guest already removed after the modal closed). The component then ran unconditionally:

  • new URL(src, guest.url.href) — throws when guest is undefined.
  • useEffect dependencies and bodies keyed on guest.id — dereference undefined.

Because the early return null only covered a missing host (not a missing guest), an undefined guest threw during render and crashed the subtree instead of degrading gracefully.

Fix: resolve the guest defensively (host ? host.guests.get(guestId) : undefined), key the effects on an optional guest?.id, gate effect bodies on guest being present, and return null when either host or guest is missing — after the hooks run, to satisfy the rules of hooks.

Test plan

  • npm run test -w packages/uix-host-react (39 passed, incl. 7 new GuestUIFrame tests)
  • Verify an undefined/unavailable guest renders nothing instead of crashing the host UI.

Valeria and others added 2 commits June 30, 2026 16:38
Guard against a missing host or guest before resolving the frame URL and
attaching the UI, so an unavailable guest renders null instead of throwing.
Hooks now run unconditionally to satisfy the rules of hooks.

Add unit tests for GuestUIFrame and a jest moduleNameMapper to strip the
".js" extension from relative imports.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@valeriat-ens valeriat-ens changed the title fix(host-react): prevent GuestUIFrame crash when guest is undefined [SITES-35203] fix(host-react): prevent GuestUIFrame crash when guest is undefined Jun 30, 2026
@fe-lix-

fe-lix- commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@valeriat-ens I have added some E2E test.

…ined-guest-crashes-cfe

# Conflicts:
#	e2e/host-app/src/App.js
@fe-lix-
fe-lix- merged commit 7f49ae6 into adobe:main Jul 23, 2026
4 checks passed
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.

3 participants