EFFECT_TARGET
An effect does not fit the element it is on, or two owners compete for one element, layer or copy.
On this page
EFFECT_TARGET: "{effect}" applies to "{target}" onlyWhy it happens
- A media effect is on an element that is not
imgorvideo. Effects withmedia: true, such asimage,rippleandbend, draw only on those, so the target in the message isimg, video. The instance becomesfailedand the element stays plain DOM. - The element does not match the
onselector of the definition. The target in the message is that selector. - Setup reads
ctx.mapin an effect withoutmedia: true. This one is thrown inside setup and reported as an error,"{effect}" reads ctx.map: declare media: true, and the instance fails. - A second Diorama app finds an element the first app already owns:
element is taken by another app. Two apps never share an element, so the second one skips it. - Two effects on one element call
ctx.place()withreplace: true. The later object is hidden:"{effect}": the element already has a replace object; this one is hidden.
In development builds the same code also reports these cases:
- Two effects pose one layer with
ctx.pose(), and the later pose wins. app.effects.take()runs on an element whose copy is already taken:the copy is taken already: one owner per element.- A copy taken without a
signalstays a ghost or veiled with no writes for 10 s, so Diorama releases it:a taken copy was abandoned. - The update of a leaving copy throws, and the copy is released.
- The element has
object-fit: noneorscale-down, which draw ascontain, anobject-positionvalue other than keywords and percentages, which draws at the center, or corners with different radii, where the largest radius is drawn.
How to fix
Put media effects on the image or video itself, not on its wrapper:
<figure data-dio="ripple"> <img src="/img/cover.avif" /></figure><figure> <img src="/img/cover.avif" data-dio="ripple" /></figure>In your own effect, declare media: true before reading ctx.map:
import { effect } from '@dioramajs/diorama'
export default effect({}, { media: true }, ({ map }) => { map.anisotropy = 4})For two apps on one page, give each its own subtree with the root option of effects(). For copies you take, pass a signal and release the copy when you are done with it.
Related
EFFECT_SETUPEFFECT_UPDATEctx.mapctx.place()app.effects.take()