scittle

Gregory Bleiker 2025-11-10T15:22:48.194359Z

Is there any way to force a x-scittle section to run before the next script tag? I'm registering a function window.bla through scittle and would like to use it in another script section later (that script is also imported and makes a call to window.bla). However, it seems that the script calling the function is loaded before the x-scittle script completes and thus can't find the function.

borkdude 2025-11-10T15:25:08.948889Z

script tags execute in the order that they appear in the page so it should work

borkdude 2025-11-10T15:25:30.463459Z

maybe if you list your source here, I can see what's going on

borkdude 2025-11-10T15:26:12.518149Z

or do you mean a next javascript script tag?

Gregory Bleiker 2025-11-10T15:35:52.231309Z

<html>

<head>
      <script type="application/javascript"
            src=""></script>
      <script type="application/javascript"
            src=""></script>
      <script type="application/x-scittle">
      (require
      '[replicant.string :as s]
      '[clojure.edn :as edn]
      '[replicant.dom :as r])
      (println "I'm loading myself")
      (defn renderelm [elem hic]

      (def el (js/document.getElementById elem))
      (println elem)
      (println el)
      (r/render el (edn/read-string hic))
      )
      
      (set! (.-renderelem js/window) renderelm)

      </script>

</head>
<body>
      <div data-signals="{game_id: '', test_hiccup: '[:p &quot;iiiiihiii&quot;]'}"></div>
      <section class="section">
            <div class="container has-text-centered">
                  <div id="replicanttest" data-text="window.renderelem('replicanttest', $test_hiccup)"></div>
            </div>
      </section>
</body>
<script type="module" src=""></script>

</html>

Gregory Bleiker 2025-11-10T15:38:21.173329Z

I'm registering renderelem in the head part. For safety I'm loading datastar after body. The data-text attribute gets triggered by datastar. Still it can't find window.renderelem

borkdude 2025-11-10T15:38:50.502439Z

the issue here is that datastar is probably earlier in processing the stuff than scittle has loaded stuff

Gregory Bleiker 2025-11-10T15:39:23.212379Z

exactly. But how come as the x-scittle stuff is in the head

borkdude 2025-11-10T15:39:43.357309Z

because scittle doesn't control your whole html page and your browser

Gregory Bleiker 2025-11-10T15:40:31.010219Z

it might also be a datastar problem (maybe it doesn't allow access to custom properties)

borkdude 2025-11-10T15:40:32.044129Z

scittle tags are processed on DOMContentLoaded https://github.com/babashka/scittle/blob/5b3a3acb5433a80b0e7560b559b050693115e018/src/scittle/core.cljs#L139

borkdude 2025-11-10T15:40:40.631009Z

but you can fire that thing earlier if you want to

😮 1
Gregory Bleiker 2025-11-10T15:42:16.303029Z

that would be nice! My alternative route would be to include datastar in x-scittle by manipulating the dom

borkdude 2025-11-10T15:42:49.524419Z

you can just call scittle.core.disable_autoeval or whatever it's called and then call scittle.core.eval_script_tags before you even load datastar in the next script tag

borkdude 2025-11-10T15:43:03.635579Z

in a javascript tag

borkdude 2025-11-10T15:43:07.175269Z

before the x-scittle tags

borkdude 2025-11-10T15:43:14.390719Z

or after

borkdude 2025-11-10T15:43:19.158609Z

since they must appear in the page first

borkdude 2025-11-10T15:43:48.824709Z

so maybe first list the x-scittle tags to ensure they exists. then disable auto eval in a javascript tag. then load scittle. then call eval-script-tags

borkdude 2025-11-10T15:44:53.794329Z

no sorry. you must first load scittle since you need scittle to stop auto-eval

borkdude 2025-11-10T15:45:17.423929Z

so: • scittle load tag • disable auto eval • list x-scittle tags • call scittle.eval_script_tags

borkdude 2025-11-10T15:45:22.721149Z

and then load datastar

borkdude 2025-11-10T15:45:49.743029Z

note that eval_script_tags is async for src="foo.cljs"

borkdude 2025-11-10T15:46:08.548949Z

you can also defer datastar maybe with defer=true

borkdude 2025-11-10T15:50:58.180789Z

this may also work:

<script type="module">
  await scittle.core.eval_script_tags();
  await import("");
</script>

Gregory Bleiker 2025-11-10T15:51:35.604759Z

trying that right now

Gregory Bleiker 2025-11-10T16:01:35.746669Z

this works, but the x-scittle is loaded twice (probably once again on dom loaded). I think I should be able to figure that out.

Gregory Bleiker 2025-11-10T16:01:51.201329Z

Probably just disable the auto-eval?

borkdude 2025-11-10T16:01:58.935839Z

as I said earlier:

<script type="module">
  scittle.core.disable_auto_eval();
  await scittle.core.eval_script_tags();
  await import("");

</script>

Gregory Bleiker 2025-11-10T16:02:10.448439Z

Thanks a lot for your continuing help!

borkdude 2025-11-10T16:09:23.916379Z

what you are seeing here is that datastar is setting the text of the replicant id element with the result of replicant.render (which is a dom element seemingly). interesting mix of technologies ;)

Gregory Bleiker 2025-11-10T16:10:09.531719Z

and doesn't work 🤣

borkdude 2025-11-10T16:10:24.966519Z

well, it works, but probably not how you want it ;)

Gregory Bleiker 2025-11-10T16:10:44.946989Z

but what does work is to have another div which sets the target div content