Skip to content

[Feature]: Add configurable timeout for getContentCards() method #308

@glc-helmbarki

Description

@glc-helmbarki

What problem are you facing?

The getContentCards() method currently lacks a built-in timeout mechanism, which can lead to indefinite loading states in poor network conditions.

// This promise can hang indefinitely
const cards = await Braze.getContentCards();
  • No timeout parameter available
  • No automatic rejection after X seconds
  • Forces developers to implement manual timeout workarounds

In production apps, users on slow connections (3G, congested networks, corporate firewalls) may experience:

  • Infinite loading spinners
  • Poor user experience
  • Unable to access cached content while waiting

Workarounds

We're forced to implement manual timeouts:

 timeoutRef.current = setTimeout(() => setIsLoading(false), 5000);

Ideal Solution

// Option 1: Global configuration
Braze.configure({
  contentCardsTimeout: 5000 // milliseconds
});

// Option 2: Per-call configuration
const cards = await Braze.getContentCards({
  timeout: 5000
});

// Option 3: Separate method
const cards = await Braze.getContentCardsWithTimeout(5000);

Add native timeout support with:

  • Configurable duration
  • Proper error handling
  • Fallback to cache on timeout
  • Clear timeout vs network error distinction## Additional Context

Other Information

Many other SDKs provide timeout mechanisms:

  • Firebase: Configurable timeouts
  • Segment: 30s default timeout
  • Amplitude: Built-in retry with backoff

This feature would greatly improve developer experience and app reliability.

  1. Using only getCachedContentCards() - But we need fresh data
  2. Event-based approach - Still no guarantee of response
  3. Manual Promise.race() - Works but feels like a hack

Would the team consider adding this feature? Happy to contribute a PR if you provide guidance on the preferred approach.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions