Skip to content

Nt 3336 optimized entry web hangs in loading state when experience api is blocked or errors#315

Open
Lotfi Anwar L Arif (Lotfi-Arif) wants to merge 6 commits into
mainfrom
NT-3336-optimized-entry-web-hangs-in-loading-state-when-experience-api-is-blocked-or-errors
Open

Nt 3336 optimized entry web hangs in loading state when experience api is blocked or errors#315
Lotfi Anwar L Arif (Lotfi-Arif) wants to merge 6 commits into
mainfrom
NT-3336-optimized-entry-web-hangs-in-loading-state-when-experience-api-is-blocked-or-errors

Conversation

@Lotfi-Arif

@Lotfi-Arif Lotfi Anwar L Arif (Lotfi-Arif) commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Previously, OptimizedEntry could remain in a loading state forever when an Experience API request never produced a usable result. If the request failed, timed out, or was blocked by something like an ad blocker, visitors could be left looking at a blank section instead of baseline content.
This change makes loading depend on one explicit signal: whether an Experience request is currently in flight. It uses the experienceRequestState signal from core-sdk (idle -> pending -> success | failed) and updates useOptimizedEntry to exit loading whenever the request is no longer pending.
That means:

  • pending keeps showing the loading fallback
  • success renders the resolved optimized content
  • failed renders baseline content
  • idle also renders baseline content, covering cases where no request was ever started

This closes the infinite-loading behavior for failed requests, blocked requests, consent-gated setups, and cases where no optimization-triggering event is ever sent. It also simplifies the rendering contract: loading now means only “an Experience API request is in progress,” not “optimization might still happen later.”

Additionally, reset() now restores experienceRequestState to idle, and the Experience queue updates selectedOptimizations and request success atomically so React consumers do not observe an inconsistent intermediate state.

… API outcomes

Introduces a writable `experienceRequestState` signal in `core-sdk` that
transitions through `idle -> pending -> success | failed` as the Experience
API request progresses. `ExperienceQueue.upsertProfile` writes the signal on
each request; success is published in the same reactive batch as the output
signals so consumers never observe stale data. Failure is classified as
`timeout` (AbortError) or `api-error` (all other throws).

Exposes the signal read-only on `CoreStateful.states.experienceRequestState`
and exports `ExperienceRequestState` and `ExperienceRequestFailureReason`
from the package public API.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ails

Subscribes useOptimizedEntry to experienceRequestState and sets
experienceRequestFailed when the status is 'failed'. Adds that flag as a
third escape hatch in the isContentReady expression alongside canOptimize
and !optimizationPossible, so OptimizedEntry renders baseline content
immediately on API errors, timeouts, or network blocks rather than staying
in the loading state indefinitely.

Updates sdkTestUtils createRuntime to expose a controllable
experienceRequestState observable and setExperienceRequestState helper, and
adds the signal to createOptimizationSdk's default states so all test paths
have it available.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents the experienceRequestState signal — the state machine, transition
rules, what failure cases it covers (adblocker, timeout, 4xx/5xx), what it
does not cover (no page() call ever made), the consumer pattern used in
useOptimizedEntry, and the cross-platform contract all SDK implementations
must honour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread documentation/concepts/experience-request-state.md Outdated
Comment thread packages/web/frameworks/react-web-sdk/src/optimized-entry/useOptimizedEntry.ts Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we're good now 😃

…ntry and tests

This update introduces the `experienceRequestState` signal into the `OptimizedEntry` component and its associated tests. The state transitions are now handled to reflect loading, success, and failure scenarios, ensuring that the component behaves correctly based on the API request outcomes. Additionally, the tests have been updated to utilize the new `setExperienceRequestState` helper for better control over the experience request lifecycle.
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