This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: capacitor-deep-link-cold-boot-fence

Capacitor 7 Deep-Link Decoupled Cold-Boot Fencing Standard

Enforces an atomic staging queue and synchronization fence between native platform URI activation events and web runtime bootstrap in Capacitor 7 applications. Guarantees that cold-boot links retrieved via getLaunchUrl() and runtime appUrlOpen events are sequentially buffered and dispatched only after routing and authentication state machines declare readiness.

Prohibited Anti-Pattern: Registering appUrlOpen Inside Lazy-Loaded Component Mounts Dropping Cold-Boot Activations

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Capacitor 7 Deep-Link Decoupled Cold-Boot Fencing Standard - Enforces an atomic staging queue and synchronization fence between native platform URI activation events and web runtime bootstrap in Capacitor 7 applications. Guarantees that cold-boot links retrieved via getLaunchUrl() and runtime appUrlOpen events are sequentially buffered and dispatched only after routing and authentication state machines declare readiness.
globs: src/main.ts, src/main.tsx, src/index.ts, src/index.tsx, src/**/deep-link*.ts, src/**/deeplink*.ts, src/**/router*.ts, src/**/App.tsx, src/**/App.vue
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/capacitor-deep-link-cold-boot-fence"
---

# Capacitor 7 Deep-Link Decoupled Cold-Boot Fencing Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Registering appUrlOpen Inside Lazy-Loaded Component Mounts Dropping Cold-Boot Activations

## System Constraints
You are a Principal Mobile Architect enforcing Capacitor 7 Deep-Link Decoupled Cold-Boot Fencing. Mandate atomic FIFO queuing of incoming platform URI activations at root bundle execution before framework hydration, eliminating race conditions between native intent delivery and web router readiness.

## Strict Guidelines
- Engineers MUST ALWAYS initialize deep-link listeners (`App.addListener('appUrlOpen', ...)`) and query `App.getLaunchUrl()` in the synchronous root entry point (e.g., `main.ts`) before framework initialization.
- Engineers MUST NOT attach `appUrlOpen` listeners solely inside reactive component lifecycles (e.g., React `useEffect`, Vue `onMounted`, Angular `ngOnInit`) or within lazy-loaded route chunks.
- Services MUST buffer all incoming URI events in an append-only FIFO queue fenced behind an explicit runtime readiness barrier.
- Engineers MUST deduplicate cold-boot URLs retrieved from `App.getLaunchUrl()` against `appUrlOpen` event broadcasts to prevent double-navigation execution.
- Components NEVER execute raw URI handling logic directly; they must register destination handlers through the centralized, fenced deep-link coordinator.

## Bad vs Good Implementations
### Decoupled Cold-Boot Fenced Queue vs Component Lifecycle Listener

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: If the app is cold-booted via a Universal Link or custom scheme, Capacitor dispatches the native intent or provides it via getLaunchUrl before React renders AppRoutes. Because the listener is registered late inside useEffect, the initial navigation event is dropped completely.
```typescript
import React, { useEffect } from 'react';
import { App } from '@capacitor/app';
import { useNavigate } from 'react-router-dom';

// ANTI-PATTERN: Listener is bound inside a lazy-loaded or delayed component lifecycle.
// Cold-boot intent fires before this component mounts, losing the launch URL.
// Also fails to query App.getLaunchUrl() and lacks replay protection.
export const AppRoutes: React.FC = () => {
  const navigate = useNavigate();

  useEffect(() => {
    const listener = App.addListener('appUrlOpen', (event) => {
      const slug = event.url.split('example.com')[1];
      if (slug) {
        navigate(slug);
      }
    });

    return () => {
      listener.then((handle) => handle.remove());
    };
  }, [navigate]);

  return <div>Application Routed Content</div>;
};
```

#### Production Standard (Correct)
> **Standard**: The DeepLinkFenceCoordinator initiates native event binding and checks getLaunchUrl() at import time in main.ts. URLs arriving during bootstrap are preserved in a deterministic FIFO queue. Once router and auth pipelines finish initializing, releaseFence() safely flushes pending deep-links without drops or double executions.
```typescript
import { App, URLOpenListenerEvent } from '@capacitor/app';

type DeepLinkHandler = (url: string) => Promise<void> | void;

class DeepLinkFenceCoordinator {
  private queue: string[] = [];
  private isFenced = true;
  private handler: DeepLinkHandler | null = null;
  private processedUrls = new Set<string>();

  constructor() {
    this.initImmediateCapture();
  }

  private initImmediateCapture(): void {
    // 1. Synchronously capture runtime events from boot
    App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => {
      this.enqueue(event.url);
    });

    // 2. Poll initial launch URL for cold-boots and queue atomically
    App.getLaunchUrl().then((launchUrl) => {
      if (launchUrl?.url) {
        this.enqueue(launchUrl.url);
      }
    }).catch((err) => {
      console.error('[DeepLink] Failed to retrieve launch URL', err);
    });
  }

  private enqueue(url: string): void {
    if (this.processedUrls.has(url)) return;
    this.processedUrls.add(url);

    if (this.isFenced || !this.handler) {
      this.queue.push(url);
    } else {
      this.handler(url);
    }
  }

  // Called once router and auth state machine are confirmed ready
  public releaseFence(readyHandler: DeepLinkHandler): void {
    this.handler = readyHandler;
    this.isFenced = false;

    while (this.queue.length > 0) {
      const url = this.queue.shift();
      if (url) {
        this.handler(url);
      }
    }
  }
}

export const deepLinkFence = new DeepLinkFenceCoordinator();
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Capacitor 7 Deep-Link Decoupled Cold-Boot Fencing Standard

Capacitor 7 Deep-Link Decoupled Cold-Boot Fencing Standard defines an industrial-grade behavioral standard for mobile engineering. Enforces an atomic staging queue and synchronization fence between native platform URI activation events and web runtime bootstrap in Capacitor 7 applications. Guarantees that cold-boot links retrieved via getLaunchUrl() and runtime appUrlOpen events are sequentially buffered and dispatched only after routing and authentication state machines declare readiness. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Registering appUrlOpen Inside Lazy-Loaded Component Mounts Dropping Cold-Boot Activations Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftRegistering appUrlOpen Inside Lazy-Loaded Component Mounts Dropping Cold-Boot ActivationsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS initialize deep-link listeners (`App.addListener('appUrlOpen', ...)`) and query `App.getLaunchUrl()` in the synchronous root entry point (e.g., `main.ts`) before framework initialization.

Engineers MUST ALWAYS initialize deep-link listeners (`App.addListener('appUrlOpen', ...)`) and query `App.getLaunchUrl()` in the synchronous root entry point (e.g., `main.ts`) before framework initialization.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT attach `appUrlOpen` listeners solely inside reactive component lifecycles (e.g., React `useEffect`, Vue `onMounted`, Angular `ngOnInit`) or within lazy-loaded route chunks.

Engineers MUST NOT attach `appUrlOpen` listeners solely inside reactive component lifecycles (e.g., React `useEffect`, Vue `onMounted`, Angular `ngOnInit`) or within lazy-loaded route chunks.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Services MUST buffer all incoming URI events in an append-only FIFO queue fenced behind an explicit runtime readiness barrier.

Services MUST buffer all incoming URI events in an append-only FIFO queue fenced behind an explicit runtime readiness barrier.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Engineers MUST deduplicate cold-boot URLs retrieved from `App.getLaunchUrl()` against `appUrlOpen` event broadcasts to prevent double-navigation execution.

Engineers MUST deduplicate cold-boot URLs retrieved from `App.getLaunchUrl()` against `appUrlOpen` event broadcasts to prevent double-navigation execution.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER execute raw URI handling logic directly

Components NEVER execute raw URI handling logic directly; they must register destination handlers through the centralized, fenced deep-link coordinator.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Capacitor 7 Deep-Link Decoupled Cold-Boot Fencing Standard critical for AI coding assistants?

Enforces an atomic staging queue and synchronization fence between native platform URI activation events and web runtime bootstrap in Capacitor 7 applications. Guarantees that cold-boot links retrieved via getLaunchUrl() and runtime appUrlOpen events are sequentially buffered and dispatched only after routing and authentication state machines declare readiness. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Registering appUrlOpen Inside Lazy-Loaded Component Mounts Dropping Cold-Boot Activations) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Capacitor