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

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

Open
neilcode opened this issue Jan 6, 2025 · 0 comments
Open

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

neilcode opened this issue Jan 6, 2025 · 0 comments

Comments

@neilcode
Copy link

neilcode commented Jan 6, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant