Comments (5)
I could be wrong because your code samples are incomplete, but it appears that you are attempting to mix Turbo Drive with Turbo Streams.
Turbo.visit
is meant for Turbo Drive. It is intended for navigating to new pages smoothly.
Returning a text/vnd.turbo-stream.html
response is meant to be used as part of Turbo Streams. It allows you to have your back end tell your front end to append, prepend, replace, update, remove, insert before, insert after, morph, or refresh a DOM element by ID. These streams can be sent via websockets, or (as it appears you intend) via javascript AJAX calls. If you want to initiate a turbo stream via javascript, you want to do something like this:
const response = await fetch('/api/get/list', {
method: 'get',
headers: {
'Accept': 'text/vnd.turbo-stream.html',
}
})
const html = await response.text();
Turbo.renderStreamMessage(html)
As discussed here, this is made easier by using the @rails/request.js library.
Generally, this should only be necessary if you are wiring up client-side DOM events other than link clicks and form submits to something on your server. For example, loading dependent selects as discussed here.
It might help if you can share more about your use case. I suspect that the progress bar is not going away because your server isn't responding with what is expected from the Turbo.visit
call.
from turbo.
Indeed, if you look at
turbo/src/observers/stream_observer.js
Line 47 in c339144
turbo/src/http/fetch_request.js
Line 155 in c339144
from turbo.
Thanks for your response, yes I know using the fetch api would be useful, but i was experimenting with some infinite scroll and came accross using the Turbo.visit
with turbo-stream
header and it was very useful in simple cases where the response would just be a turbo-stream
.
<turbo-stream action="append" target="list">
<template>
<?php $sno = $offset + 1;
foreach ($list as $record) : ?>
<tr>
<td><?= $sno ?></td>
<td><?= "{$record->first_name} {$record->last_name}" ?></td>
<td><?= $record->member_id ?></td>
<td><?= $record->email ?></td>
<td><?= $record->gender ?></td>
<td><img src="<?= $record->photo ?>" alt=""></td>
</tr>
<?php $sno++;
endforeach; ?>
</template>
</turbo-stream>
The thing is there is no issue such like this in the v7.3 and i checked the code you referred to the in the v7.3 and its just the same. Also checked it with some delay <?php sleep(3) ?>
in the backend, and the progress bar works in v7.3 and not like its completely off.
Unless I am sending some other data that i would need to work --(like disabling any more request if a particular total is reached)-- with in js, i would happily just add the single line Turbo.visit
and forget about anything else.
from turbo.
Ah so you were trying to use Turbo.visit as an easy way to initiate a GET that returns a turbo stream? Interesting. Looks like that may only work by coincidence in some versions - probably not designed to work that way. Right?
from turbo.
Okay i was following the trail and in the v8 there is some missing code that is present in the v7.x.
8.x
turbo/src/http/fetch_request.js
Line 144
in
c339144
Line 340
in
c339144
Line 202
in
c339144
turbo/src/core/native/browser_adapter.js
Line 57
in
c339144
turbo/src/http/fetch_request.js
Line 144 in c339144
Line 340 in c339144
Line 202 in c339144
turbo/src/core/native/browser_adapter.js
Line 57 in c339144
7.x
turbo/src/http/fetch_request.ts
Line 120
in
4593d06
...
Line 251
in
4593d06
turbo/src/core/native/browser_adapter.ts
Line 68
in
4593d06
turbo/src/http/fetch_request.ts
Line 120 in 4593d06
Line 251 in 4593d06
turbo/src/core/native/browser_adapter.ts
Line 68 in 4593d06
In v8 there is some logic in visitCompleted
and not in visitRequestFinished
and its the opposite in 7.x.
turbo/src/core/native/browser_adapter.ts
Line 71 in 4593d06
turbo/src/core/native/browser_adapter.js
Line 59 in c339144
This intended?!?
-- And the progress bar is hidden if i place the code in the function, but unsure how it will affect others!
from turbo.
Related Issues (20)
- turbo-confirm doesn't work on links without a turbo-method HOT 1
- Window.fetch has been overwritten by Stimulus HOT 5
- Adding stimulus breaks a test...why?
- Preserve scroll position when morphing turbo frames
- turbo:morph-element fires twice
- Form not displaying errors on page HOT 2
- Morph with infinite scroll
- turbo-frame with text only not rendering on restoration visits
- How to prevent element from being removed during morph? HOT 3
- data-turbo="false" misbehaviour
- Drive: Navigating back from a 3xx redirect to an external page makes turbo show 'loading' forever
- Morph skip render some elements
- Duplicating DOM elements with `before` and `after` turbo streams actions
- Reconsider adding `turbo:after-stream-render` event HOT 3
- Input field missing from form with errors, even though it is in the HTML response
- Turbo does not work with Declarative Shadow DOM HOT 1
- It's unfortunate that Turbo overloads the concept of "action", is it too late to rename "Turbo actions"? HOT 1
- Turbo Frame + Nginx Cache
- Turbo Stream rendering plain text html instead of replacing content in targeted turbo frame HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turbo.