Class: Phlex::Reactive::DeferredRenderJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/phlex/reactive/deferred_render_job.rb

Overview

The push lane's render leg (issue #165): rebuild the deferred component from its identity payload OFF the request thread, render it, and broadcast the result DURABLY to the one-shot stream the actor's subscribes to. Durable is load-bearing: pgbus's since-id replay only covers PGMQ-persisted messages, and that replay is what closes the broadcast-before-subscribe race.

Every broadcast payload ends with a remove of the client's source element (id reactive-defer-src-), so the subscription tears itself down with the content it delivered — no client-side arrival bookkeeping.

A gone record (deleted while the job sat in the queue) or render? false broadcasts the CLEANUP instead: reactive:js ops clearing the pending markers + the teardown. The shimmer must never hang, and a deleted record must not retry (rescued, not retried — there is nothing to render).

NOT eager-loaded (see the loader config in phlex/reactive.rb): the class body needs ActiveJob::Base, which isn't a gem dependency — the constant is only referenced behind Phlex::Reactive.defer_push_capable?.

Instance Method Summary collapse

Instance Method Details

#perform(component_class_name, payload, stream_key, target, morph) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/phlex/reactive/deferred_render_job.rb', line 27

def perform(component_class_name, payload, stream_key, target, morph)
  klass = component_class_name.constantize
  # Defense in depth (the args come from our own enqueue, but fail
  # closed): only reactive components may be rebuilt and rendered. This is
  # a PROGRAMMING error (a bad enqueue), not a recoverable runtime failure
  # — it raises loudly and broadcasts NOTHING, OUTSIDE the render rescue
  # below (a component with actions can't be forged past the signed
  # identity anyway, so this never fires for a real defer).
  unless klass.respond_to?(:reactive_action?) && klass.include?(Phlex::Reactive::Component)
    raise ::ArgumentError,
      "#{component_class_name} is not a reactive component — refusing the deferred render"
  end

  render_and_broadcast(klass, payload, stream_key, target, morph)
end