Skip to content

fix: deep link race condition — fires before providers initialized on cold start #4763

Closed

Description

@beastoin

Problem

In app/lib/core/app_shell.dart, initDeepLinks() runs in initState() (line 294) but provider initialization runs in addPostFrameCallback (line 296 — later in the lifecycle):

@override
void initState() {
  initDeepLinks();  // ← deep link listener starts HERE

  WidgetsBinding.instance.addPostFrameCallback((_) async {
    // ← providers initialized HERE (later)
    context.read<AppProvider>().setAppsFromCache();
    context.read<MessageProvider>().refreshMessages();
    // ...
  });
  super.initState();
}

PR #4737 adds getInitialLink() inside initDeepLinks() which processes the launch URI immediately — before addPostFrameCallback fires. This means:

  1. context.read<AppProvider>().getAppFromId(id) returns null for valid app IDs (cache not loaded yet)
  2. User sees "App not available" error on a valid deep link
  3. Or worse: if a provider hasn't been registered in the ancestor tree yet, context.read<T>() throws

This affects ALL deep link routes on cold start (app launched by a link), not just /tasks.

Reproduction

  1. Force-kill the Omi app
  2. Open h.omi.me/apps/{valid-app-id} from another app or browser
  3. App launches → "App not available" error (because cache wasn't loaded yet)

Suggested fix

Defer initial link processing until after providers are ready:

@override
void initState() {
  super.initState();
  WidgetsBinding.instance.addPostFrameCallback((_) async {
    // Initialize providers first
    if (context.read<AuthenticationProvider>().isSignedIn()) {
      context.read<AppProvider>().setAppsFromCache();
      // ...
    }
    // THEN start deep link handling
    await initDeepLinks();
  });
}

Or use a Completer that openAppLink awaits before processing.

Context

Found during deep link audit of PR #4737. Credit: @kenji's audit.

Sub-issue of #4724.

Activity

  1. added
    ux-polish
    maintainer
    p1
    on Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintainerp1ux-polish

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions