No listeners for <event> in DOMContentLoaded
- Dominant language
- JavaScript
- Stars
- 6.8k
- Forks
- 573
- PR merge metrics
- No merged PRs in 30d
Description
### Expected behavior
Expecting listeners to bet ready when DOMContentLoaded is fired.
### Actual behavior
Getting warning "No listeners for myevent"
### Steps to reproduce behavior
index.js
```
app.use(require('./stores/app'))
app.use(require('./stores/user'))
```
app.js
```
emitter.on('DOMContentLoaded', function () {
// Do app-level stuff
emitter.emit('user:myevent', {})
```
user.js
```
emitter.on(`user:myevent`, function (data) {...})
```
Have to wait a bit before the listener is registered.
setTimeout(() => {emitter.emit('user:myevent', {})}, 10)
Contributor guide
Research direction
Start by reproducing the warning with the index.js, app.js, and user.js examples from the issue, then trace when each listener is registered relative to DOMContentLoaded. Done means the user:myevent listener is ready when the event fires and the warning no longer appears without using setTimeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100