Skip to content

Execution Order ​

What happens first and what happens next, from a click to the updated screen. Once this is clear, questions like "why did the screen flash?" or "why was my second call refused?" answer themselves.

The big picture ​

1. Before triggering: debounce, interval, confirmation ​

OrderMechanismEffect
①data-linker-debounceWait for the user to stop
②Minimum interaction interval (0.8 s by default)A second click too soon: buttons drop it, fields keep the latest value and send it later
③data-linker-confirmContinue only after the user confirms
④The form's cancelable submit eventGuards like FileDrop can stop it

2. Queuing: one call at a time per mount point ​

The front end keeps a Promise queue per @linker mount point. Calls on the same mount point are sent and applied in order:

  • A second request can never return first and overwrite the first one's result.
  • In Stateful mode the revs line up.
  • Different mount points don't wait for each other and can run in parallel.
#orders mount point:  search ──▶ search ──▶ delete       (in order)
#chart  mount point:  load ──▶ load                      (parallel with the above)

3. Server: locks and revs (Stateful) ​

  • The lock covers read → dispatch → write on the same instance.
  • A request carrying an old rev (for example, two tabs sharing the same HTML) gets conflict.
  • dd() doesn't advance the rev or store state.

Stateless has no instance lock; calls to the same URL can run in parallel. Write correctness comes from DB transactions, unique constraints and idempotency.

4. Response: state first, then the pipeline ​

On success the order is fixed:

  1. Each key in data is written to client state → subscribed data-state-* bindings re-render synchronously.
  2. The pipeline runs in order.

The other way round, dom.scrollTo would scroll to a screen that hasn't updated yet.

The namespace is decided at binding time, not when the response arrives, because the previous pipeline's render.fragment may already have replaced the trigger element.

5. Pipeline: in order, awaited, failures jump to catch ​

php
return $this->ok()
    ->call('ui.confirm', ['message' => 'Also send a notification email?'])   // ① waits for the user
    ->then('render.fragment', [...])                                         // ② waits for the fragment to be inserted
    ->then('dom.scrollTo', ['target' => '#list'])                            // ③
    ->catch('ui.toast', ['level' => 'error', 'message' => 'Failed to update the screen'])
    ->always('form.focus', ['target' => '#keyword']);
RuleNotes
Awaited in orderEach step (including Promises) finishes before the next starts
Starting stateCall succeeded = not failed; call failed = failed
thenRuns only when not failed
catchRuns only when failed
alwaysAlways runs
A step throws or its action isn't registeredState becomes failed; all later then steps are skipped
Limit20 steps

ui.confirm returns Promise<boolean> and the pipeline waits for it. But it only waits for the answer; cancelling does not turn the state into failed. For "stop if cancelled", put the confirmation on the trigger (data-linker-confirm), or split it into two calls.

When the call fails ​

php
return LinkerResponse::validation($errors)
    ->catch('state.set', ['scope' => 'wizard', 'key' => 'step', 'value' => 2]);
  1. Shared error handling runs first (field errors are painted).
  2. data is not written to state.
  3. The pipeline starts as failed; only catch / always run.

6. After renderBlade inserts ​

render.fragment is the most common async step in a pipeline. It counts as finished once:

innerHTML replaced
  → inline <script> in the fragment run
  → CGEvent.bind()
  → bindState()        (data-state-init → other bindings read state back)
  → renderBladeAuto()  (@renderAuto inside the fragment sends its own requests)
  → cg:rendered dispatched  (new data-linker-call, charts and seeds bind here)

So the next pipeline step (for example dom.scrollTo) sees new content that is already bound.

When the fragment fingerprint matches (unchanged), the HTML isn't replaced and scripts and bindings aren't re-run, because inline scripts aren't idempotent. cg:rendered still fires with detail.unchanged set to true. Pass fresh: true to force a full re-run.

7. Nested calls ​

An action can call another method on the same mount point through context.callLinker(). Since it already holds the queue it runs immediately rather than queuing behind itself and deadlocking. Nested calls across mount points are refused.

Common timing problems ​

SymptomCauseFix
The second call gets conflictTwo pages share one instance, or @linker sits inside a re-rendered fragmentMove the mount point to an outer block
Scrolls to the old positionYour action didn't return a Promise, so the pipeline didn't waitReturn a Promise
A field error flashes then disappearsResponses from two triggers on one element overwrote each otherAlready handled by "later cancels earlier"; make sure you don't send your own extra request
Old values reappear after savingfresh re-rendered while state still held old valuesstate.clear first, then render.fragment(fresh)
A double click submits twice—The minimum interval and busy state already prevent it; writes should still be idempotent