Skip to content

[Vue3] router.post redirect responses do not cause DOM to update #180

@neilcode

Description

@neilcode

Hello, my team's run into an interesting issue regarding POST requests that respond with redirects. We are on Rails 7.0.8.4 using Vue 3.x

Here's an example: we have two controller routes for working through a queue of "review" entities on our site. The show action shows a tabbed navbar (current_tab being the active tab in the nav). There's an optional param for search filters, and the queue prop is an array of "review" entities. Apologies for the generic nature of the code, I'm trying to redact for IP sensitivity.

      def show
        render inertia: 'Review/Show', props: {
          tab: current_tab,
          filters:,
          queue:,
        }
      end

      def complete_reviews
        reviews.each(&:complete)

        redirect_to review_path(
          tab: current_tab,
          filters: filters,
        ),
        notice: "Reviews have been marked as complete."
      end

When we execute a router.post in our javascript code, I can see the request in my Chrome inspector's network tab and I see a 302 response from the redirect. I also see that my browser follows the redirect and requests the page, receiving a 200 response. However, after receiving the 200 response, our Vue components do not update their state on the page. We have to refresh the browser tab manually to see the new application state. We have isolated this to POST requests only (using both router.post and <Link method="post">): when the request is modified to a GET with no additional code changes beyond those that would support the change in HTTP verb and using query params to send our data, everything works as intended.

According to the inertia-rails docs, Inertia-fied POST requests are intended to follow redirects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions