You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
SortableJS() requires presence of Script(type='module')
Minimal Reproducible Example
External scripts can be included through the fast_html() wrapper, like so:
app, rt=fast_app(
hdrs=(SortableJS())
)
...but this results in:
<!doctype html><html><head><title>Botifython / Another / Home </title><metacharset="utf-8"><metaname="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><scriptsrc="https://unpkg.com/htmx.org@next/dist/htmx.min.js"></script><scriptsrc="https://cdn.jsdelivr.net/gh/answerdotai/[email protected]/fasthtml.js"></script><scriptsrc="https://unpkg.com/htmx-ext-ws/ws.js"></script><scriptsrc="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><scriptsrc="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script><linkrel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css"><style>:root { --pico-font-size: 100%; }</style>
import {Sortable} from 'https://cdn.jsdelivr.net/npm/sortablejs/+esm';
proc_htmx('.sortable', Sortable.create);
<script>(function(){varsocket=newWebSocket(`ws://${window.location.host}/live-reload`);varmaxReloadAttempts=1;varreloadInterval=1000;// time between reload attempts in mssocket.onclose=function(){letreloadAttempts=0;constintervalFn=setInterval(function(){window.location.reload();reloadAttempts++;if(reloadAttempts===maxReloadAttempts)clearInterval(intervalFn);},reloadInterval);}})();</script></head><!-- ... -->
...which if you look close you will see that the JavaScript import is not
wrapped in a <script type="module"> tag resulting in <head>-leakage. In
experimenting, I find that this will fix it:
...because even though it ends up with an empty script module tag, it also wraps
the SortableJS one properly:
<!doctype html><html><head><title>Botifython / Another / Home </title><metacharset="utf-8"><metaname="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><scriptsrc="https://unpkg.com/htmx.org@next/dist/htmx.min.js"></script><scriptsrc="https://cdn.jsdelivr.net/gh/answerdotai/[email protected]/fasthtml.js"></script><scriptsrc="https://unpkg.com/htmx-ext-ws/ws.js"></script><scriptsrc="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><scriptsrc="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script><linkrel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css"><style>:root { --pico-font-size: 100%; }</style><scripttype="module">import{Sortable}from'https://cdn.jsdelivr.net/npm/sortablejs/+esm';proc_htmx('.sortable',Sortable.create);</script><scripttype="module"></script><script>(function(){varsocket=newWebSocket(`ws://${window.location.host}/live-reload`);varmaxReloadAttempts=1;varreloadInterval=1000;// time between reload attempts in mssocket.onclose=function(){letreloadAttempts=0;constintervalFn=setInterval(function(){window.location.reload();reloadAttempts++;if(reloadAttempts===maxReloadAttempts)clearInterval(intervalFn);},reloadInterval);}})();</script></head><!-- ... -->
Describe the bug
SortableJS() requires presence of Script(type='module')
Minimal Reproducible Example
External scripts can be included through the
fast_html()
wrapper, like so:...but this results in:
...which if you look close you will see that the JavaScript import is not
wrapped in a
<script type="module">
tag resulting in<head>
-leakage. Inexperimenting, I find that this will fix it:
...because even though it ends up with an empty script module tag, it also wraps
the SortableJS one properly:
It's a hack.
Expected behavior
...should result in:
Environment Information
Confirmation
Please confirm the following:
The text was updated successfully, but these errors were encountered: