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

Turbo not streaming changes properly / window.Turbo is undefined #592

Open
TaylorJonesTRT opened this issue Feb 21, 2024 · 3 comments
Open

Comments

@TaylorJonesTRT
Copy link

To begin I'm not sure if this is a turbo-rails 2.x.x issue or all around.

Whenever I attempt to have my rails app render a turbo_stream.replace, the browser instead of rendering the replacement is downloading the raw html file of the actual turbo_stream replacement.

I'm using old code from a few months back from when this was originally working (my gemfile.lock says I was on 1.5.0) back then with a new Rails app that was just scaffold-ed.

When attempting to dive into this and figure out the issue I did find out that window.Turbo is undefined in my console on the Rails app.

My controller code:

    exercise_name = exercise_params[:name]

    @exercise = Exercise.build(name: exercise_name, user_id: current_user.id)

    if @exercise.save
      update_exercise_list
    else
      render exercises_path, status: :unprocessable_entity
    end
  end

  private

  def exercise_params
    params.require(:exercise).permit(:name, :personal_best)
  end

  def update_exercise_list
    render turbo_stream: turbo_stream.replace('exercise_list',
                                              partial: 'exercises/exercise_list',
                                              locals: { exercises: current_user.exercises.order(name: :asc) })
  end

My partial view that contains the turbo frame:

  <ul class="mt-5">
    <% exercises.each do |exercise| %>
      <li>
        <%= exercise.name %>
      </li>
    <% end %>
  </ul>
<% end %>

The attached files are what my browser downloads
exercises.txt
exercises(15).txt

@TaylorJonesTRT
Copy link
Author

This still works properly in my old project but does not when I force my current project to use 1.5.0. In chrome it doesn't download a file but displays the raw html as text.

@TaylorJonesTRT
Copy link
Author

I have to do some back tracking but I was able to resolve this issue, don't believe it's anything in the package/gem itself.

@fa11enangel
Copy link

@TaylorJonesTRT please close resolved issues to help maintainers and other developers looking at issues.

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

No branches or pull requests

2 participants