Home Features Philosophy Docs Blog Errors Security Examples FAQ
DJE-054 Warning Template

document.addEventListener for djust: events (silent failure)

Error message

djust:push_event listener never fires — no error in console

All djust custom events (djust:push_event, djust:error, djust:upload:*, etc.) are dispatched on `window`, not `document`. Using document.addEventListener('djust:...') will silently never receive events. This is detected by the djust.T004 system check.

events javascript silent-failure template

Affected versions: >=0.2.0

Solutions

Before (problematic)
document.addEventListener('djust:push_event', (e) => {
    // This handler NEVER fires!
    console.log(e.detail);
});
After (fixed)
window.addEventListener('djust:push_event', (e) => {
    // Works correctly
    console.log(e.detail);
});

Before (problematic)
# Not sure if you have this bug?
After (fixed)
python manage.py djust_check --category templates
# Look for: WARNING djust.T004