ihp icon indicating copy to clipboard operation
ihp copied to clipboard

Using `autoRefresh` and `render` in the same Controller leads to white screen

Open liammcdermott opened this issue 3 months ago • 4 comments

In our IHP 1.3 project there's a Controller that uses autoRefresh to render a view until a particular field in the database changes. When that field changes it sends a redirectTo. This worked well for showing a spinner animation while waiting for something to happen, then redirecting the user after.

In IHP 1.4 (I also tried updating our project to the latest commit, too) this is no longer working. I have created an example IHP project so the issue is reproducible.

To reproduce:

  1. Start the IHP project and open it in a browser, as usual.
  2. Create a new Foo using the + New button.
  3. Click the Show link.
  4. In a second tab, open up the IHP IDE (if it isn't open already)
  5. Go to Datafoos and click the bar tickbox, so it's set to True

What I expect to happen: the user is sent to /Welcome. What actually happens: the screen is white, and on the network tab of Developer Tools I see two empty responses from the websocket.

Note: clicking refresh in the browser makes IHP send the redirect correctly, so I surmise the issue is with autoRefresh.

Here're the problematic lines of code in context. For brevity:

    action ShowFooAction { fooId } = autoRefresh do
        foo <- fetch fooId
        if not foo.bar
        then render ShowView { .. }
        else redirectTo WelcomeAction

liammcdermott avatar Oct 16 '25 19:10 liammcdermott

Thanks for reporting 👍 I'll look into this

mpscholten avatar Oct 18 '25 15:10 mpscholten

I've been debugging this just now using the project you provided. I can reproduce the issue.

It seems the empty page is the result of the redirect response body being empty:

-- Added this to AutoRefresh.hs line 125
Log.info (show (status, headers, builder))
-- => (Status {statusCode = 302, statusMessage = "Found"},[("Location","http://localhost:8000/Welcome")],"")

This is kind of the expected behavior of the code :D

It's very surprising that the redirect has worked before. It should not have worked before as it's technically not supported.

Do you have any custom JS in that project that somehow could be doing the redirect?

mpscholten avatar Oct 20 '25 02:10 mpscholten

Thanks for looking into this @mpscholten. AFAICT there isn't any custom JS in the project that does a redirect.

I'm just reverting the project back to IHP v1.3 and making sure it did work previously. Just in case I'm mis-remembering!

liammcdermott avatar Oct 22 '25 23:10 liammcdermott

In IHP v1.3 you're right that the redirect does not work. However, the behaviour is a little different: in 1.3 the websocket does not receive any empty messages, and no whitescreen is displayed. Instead IHP keeps displaying the last thing that was render-ed. Sorry for the confusion.

This is a feature request then. The use-case is I would like to show an automatically updating view while some background process is running, then redirect the user somewhere else when it's complete.

Specifically in my use-case, the application is displaying a loading spinner while a login link is sent to the user's e-mail, then advising the user if the e-mail bounced. The redirect happens if the user clicks the link sent to their e-mail and successfully logs in.

liammcdermott avatar Oct 24 '25 02:10 liammcdermott