By default the deflector attaches as soon as the page is ready. Turn that off
and you decide when:
Both are safe to call repeatedly. render() on an already-attached deflector is
a no-op, which matters because the natural place to call it is a change handler
that fires on every keystroke.
unmount() removes every listener and every element the deflector added,
leaving the form exactly as it was found — including restoring the submit
button’s original label.
Not intercepting an incident report
The most valuable use of this: some tickets must reach a human, and answering
them is worse than useless.
The reader reporting an outage sees the form they expect, with its own button
text and no notice about AI. Everyone else gets the deflector.
Prefer this to a low confidence threshold. A threshold is a guess about whether
the answer is good; this is a fact about whether the reader should be answered
at all.
A form behind a tab, an accordion, or a route change is not in the DOM when the
script runs.
Usually you need nothing: the deflector already waits up to
data-wait-for-elements-timeout (default 10s, -1 waits forever) for the form
and question field to exist. Manual rendering is for when waiting is not enough
— a form that appears, disappears and appears again, where you want the
deflector armed each time.
If the markup is present immediately but your framework replaces it on
hydration, the deflector attaches to nodes that are about to be discarded and
then silently intercepts nothing. Waiting cannot help — the elements it is
waiting for are already there.
The fix is a delay before looking at all, which does not need manual rendering:
Replacing the configuration at runtime
attach() configures and arms in one call, and replaces any deflector already
attached — so calling it twice does not leave two sets of listeners on the same
button:
Use it when the form itself changes — a different question field for a different
ticket type — rather than to toggle the deflector on and off, which is what
render() and unmount() are for.
From the npm package
Same three functions, same semantics.