element-hq / element-hq/chatterbox
Chatterbox registers two accounts when first opened, then crashes
- Dominant language
- TypeScript
- Stars
- 181
- Forks
- 25
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I'm trying to set up a self-hosted instance of Chatterbox in `invite_user` mode. When I first click on the Chatterbox button, it starts to open, creates the room, and sends the invitation, but then gets an error saying that `room is undefined` (`t is undefined` in the built version) and removes itself from the page. If I then reload the page and open Chatterbox again, it creates a second room, sends an invitation to _that_ room, and works correctly from that point on. If I simulate being a new user (by clearing site data, opening a private window, or using a different browser), it fails again, then starts working again after a reload.
The error seems to be happening in Hydrogen's `RoomViewModel` class [here](https://github.com/element-hq/hydrogen-web/blob/62332fe6a162e0ec3c6816556337728b8ba1fbcf/src/domain/session/room/RoomViewModel.js#L43), but that seems to be a result of Chatterbox passing in `undefined` as the `room`. I've managed to trace the problem to this part of `createRoomWithUserSpecifiedInConfig`: https://github.com/element-hq/chatterbox/blob/86bc29074ab771a618e3752174f5ec681b844705/src/viewmodels/ChatterboxViewModel.ts#L78-L95 It starts creating the room/invite, and waits for it to finish, but when it does, somehow the `this._sessions.rooms` map is completely empty.
**To Reproduce**
Steps to reproduce the behavior:
1. Download and extract [chatterbox-v0.5.2.tar.gz](https://github.com/element-hq/chatterbox/releases/tag/v0.5.2).
2. Edit config.json. Fill out the `homeserver` and `token` settings. Replace the `auto_join_room` setting with `invite_user`, and set it to a Matrix user ID that you control.
3. Create a basic index.html file, and add the [embed code](https://github.com/element-hq/chatterbox#embed-instructions) to it.
1. Optional: The browser's devtools get confused when Chatterbox removes its `iframe`, and won't let you look at the code that's failing anymore. To prevent this, add `HTMLIFrameElement.prototype.remove = function() { console.log('refusing to remove iframe', this); };` after the `CHATTERBOX_CONFIG_LOCATION` line.
4. Upload the contents of the `chatterbox-v0.5.2` folder to a web server, or serve it on `localhost` using something like [`httplz`](https://github.com/thecoshman/http).
5. Visit the server.
6. Click on the Chatterbox button. It will open briefly and send the invite, then self-destruct.
*OR*
1. `git clone https://github.com/element-hq/chatterbox; cd chatterbox`
2. Edit public/config.json. Fill out the `homeserver` and `token` settings. Replace the `auto_join_room` setting with `invite_user`, and set it to a Matrix user ID that you control.
3. `yarn install`
4. `yarn start`
5. Visit http://localhost:5400/
6. Click on the Chatterbox button. It will open briefly and send the invite, then self-destruct.
**Expected behavior**
Chatterbox should remain open after creating the room even if the user is opening it for the first time.
**Screenshots**
N/A. There's not really anything to take a screenshot _of_ once Chatterbox removes itself.
**Desktop (please complete the following information):**
- OS: macOS
- Browser: Firefox, Chrome
- Version: Firefox 121.0.1, Chrome 120.0.6099.234
**Smartphone (please complete the following information):**
Not tested yet.
- ~Device: [e.g. iPhone6]~
- ~OS: [e.g. iOS8.1]~
- ~Browser [e.g. stock browser, safari]~
- ~Version [e.g. 22]~
**Additional context**
I was originally testing with Chatterbox running on `http://localhost:8000`, but I've also tried running it from a real `https://` site, and am getting the same results there. I'm running Chatterbox [v0.5.2](https://github.com/element-hq/chatterbox/releases/tag/v0.5.2) (or 86bc290 when trying the dev build, but the only changes since v0.5.2 seem to be in the readme).
I have it set to use a self-hosted Synapse homeserver. When I first noticed the issue, `invite_user` was set to a user on a _different_ self-hosted Synapse, but it seems to happen even if the `invite_user` is on the same server.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the first-open flow with invite_user using the listed release steps or yarn start. Inspect createRoomWithUserSpecifiedInConfig in src/viewmodels/ChatterboxViewModel.ts:78-95 and compare it with Hydrogen's RoomViewModel.js at the referenced line, focusing on why this._sessions.rooms is empty after room creation. Done means the first opening keeps Chatterbox visible and does not create a duplicate room or invitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100