Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket fails to connect when Lookbook is mounted at root #63

Open
dmorgan-fa opened this issue Mar 1, 2022 · 5 comments
Open

Websocket fails to connect when Lookbook is mounted at root #63

dmorgan-fa opened this issue Mar 1, 2022 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@dmorgan-fa
Copy link
Contributor

dmorgan-fa commented Mar 1, 2022

Hey Mark, something that I've ran into recently:

When we mount the Lookbook engine at the root of the rails app, rather than /lookbook, websockets fail to connect and hot reloading fails.

Demo here
Console: WebSocket connection to 'ws://cable/?uid=1646144935981' failed

Edit:
I've also checked against the latest 0.6.1, and the problem is still present.

@allmarkedup
Copy link
Collaborator

@dmorgan-fa ah ok yes, I know why that will be - I haven't accounted for it being mounted like that, but it should definitely support it.

I've got another minor websocket issue I've been meaning to look at so I'll try and get them sorted together. Thanks for the report 👍

@allmarkedup
Copy link
Collaborator

@dmorgan-fa so I've spent a fair amount of time digging into this and I'm afraid to say I'm stumped :-(

I've fixed a couple of (related) issues (on main, not released yet) but I just cannot figure out why ActionCable is not connecting when the engine is mounted at root. I suspect it's something to do with Lookbook being an isolated Rails engine, and without a mount path Rails is trying to connect to the ActionCable server on the parent application or something like that. I've tried everything I can think of to work around it but nothing seems to work. Very frustrating.

As an aside, ActionCable is actually complete overkill for Lookbook, but I've not had much luck finding a (simpler) alternative. There is literally just a single 'updated' event that needs firing on the server and picking up on the client side so it's pretty annoying having to rely on a complex ActionCable setup. It's actually making me think I should investigate implementing an old-skool long-polling AJAX style 'socket' instead!

I'll label this as help wanted in case anyone with more websocket skills than me can help and I'll keep you updated if I stumble across a fix.

@allmarkedup allmarkedup added bug Something isn't working help wanted Extra attention is needed labels Mar 1, 2022
@dmorgan-fa
Copy link
Contributor Author

No worries, thanks for the quick reply Mark!
Sorry to hear it's much more of a pain than we thought it would be 😅 As a workaround, I've remounted at /lookbook and stuck in a redirect, so there's no urgency on this. Have a good weekend 👋

@allmarkedup
Copy link
Collaborator

@dmorgan-fa so I believe I've finally fixed this issue 😃

The latest release (1.0.7) has a bunch of other websocket-related fixes in it, and off the back of that I thought I'd see if I could tackle this again to finally close it off. It's not released yet but I've just pushed a change to main that means the websocket should now correctly trigger the UI updates even when Lookbook is mounted at root.

I'm going to go ahead and close this now and will include the fix the next release. Thanks again for bringing it to my attention!

@coorasse
Copy link

coorasse commented Jul 10, 2024

We are experiencing the same problem on version 2.2.1. Mounting lookbook at /lookbook instead of / solved it.
Let me know if I can help by providing examples.

@Spone Spone reopened this Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants