hotwired / turbo-ios

iOS framework for making Turbo native apps
MIT License
891 stars 87 forks source link

Add redirected to visit response #225

Open olivaresf opened 2 months ago

olivaresf commented 2 months ago

This reverts https://github.com/hotwired/turbo-ios/pull/155 which assumed that Turbo Native was using the same algorithm as Turbo to set flash notices.

When a redirection with a responseHTML would happen (e.g. a form submission), Turbo Native receives something like the following:

← visitProposed [
    "location": http://localhost:45678/submit_redirected, 
    "timestamp": 1725557992593, 
    "options": {
        action = replace;
        response =     {
            redirected = 1;
            responseHTML = "{HTML with flash notice}";
            statusCode = 200;
        };
        shouldCacheSnapshot = 0;
    }
]

This usually gets turned into a JavaScript visit and then handed over to the bridge, which begins the visit by calling visitLocationWithOptionsAndRestorationIdentifier.

However, when transforming this proposal JS -> Swift (for processing) and back to JS (for bridge consumption), visitProposed["options"]["response"]["redirected"] was being lost. This caused responseHTML to be ignored and a replace visit to be proposed instead.

By adding redirected to VisitResponse the behavior is now correct.