Emitting pushState is a no-op in a route handler
- Dominant language
- JavaScript
- Stars
- 6.8k
- Forks
- 573
- PR merge metrics
- No merged PRs in 30d
Description
### Expected behavior
In choo v6.8.0, emitting `pushState` (e.g. `emit('pushState', '/')`) in a route handler should have the [documented behaviour](https://github.com/choojs/choo#pushstatestateeventspushstate) of navigating to the indicated page.
My use case is to redirect the user to the homepage from f.ex. the login page if the user is already logged in.
### Actual behavior
When emitting this event in a route handler, it appears to do nothing. Instead I defer the event to be emitted asynchronously, which makes it work: `setTimeout(() => {emit.global('pushState', '/')}, 0)`
### Steps to reproduce behavior
Emit the `pushState` event in a route handler, in my experience it'll be a no-op:
```
emit('pushState', '/')
```
Contributor guide
Research direction
Start by tracing the route handler's `emit('pushState', '/')` path and compare it with the documented `pushState` behavior. Reproduce the issue using the example from the report, then verify that emitting the event synchronously navigates to the homepage rather than requiring the asynchronous workaround.
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