stimulusreflex / cable_ready

Use simple commands on the server to control client browsers in real-time
https://cableready.stimulusreflex.com
MIT License
755 stars 70 forks source link

Can't make `redirect_to` with `cablecar` functionnal with `rc2` #272

Closed jibees closed 1 year ago

jibees commented 1 year ago

This code is functional for pre10:

        render operations: cable_car.redirect_to(
          url: MY_URL
        )

Response is:

[{"url":"/","operation":"redirectTo"}]

Unfortunately, when bumping to rc2, with the following code:

        render cable_ready: cable_car.redirect_to(
          url: MY_URL
        )

(only changing deprecated operations: to cable_ready) it does not redirect my app, probably because the response is actually empty.

(at least json seems fine)

marcoroth commented 1 year ago

Thanks for bringing this to our attention @jibees!

As we discussed this on Discord, it only surfaced in combination with mrujs when submitting a form. mrujs added a Accept: application/vnd.cable-ready.json header to the request which caused some issues because we recently changed the CableReady MIME-Type to text/vnd.cable-ready.json in #260.

Luckily the CableCar plugin for mrujs allows the MIME-Type to be configured, like:

mrujs.start({
  plugins: [
    new CableCar(CableReady, { mimeType: "text/vnd.cable-ready.json" })
  ]
})

This seems to solve the issue. @jibees is going to open a pull request on mrujs to update the default MIME-Type for the CableCar plugin in: https://github.com/KonnorRogers/mrujs/blob/86ec3ddea227c5125b2aa946af8e27837d4dae36/plugins/src/cableCar.ts#L16

Heads-up @KonnorRogers!

I'm going to close this issue! Thank you!

jibees commented 1 year ago

After some research, it appears that the underlying issue was something related to Content-Type.

Actually, cable_ready changed its default ContentType recently (reference: https://github.com/stimulusreflex/cable_ready/pull/260)

And the form was actually submitted/handled via mrujs integrated with CableCar which clearly precise that form with accept header "application/vnd.cable-ready.json, */*" will be handled Source: https://mrujs.com/how-tos/integrate-cablecar

So, it's not actually a cable_ready issue. Closing here!

Thanks for the great debugging session @marcoroth ! That was very pleasant!

jibees commented 1 year ago

Just opened a PR on mrujs: https://github.com/KonnorRogers/mrujs/pull/209 !

marcoroth commented 1 year ago

Awesome, thank you @jibees!