lubomirblazekcz / nette-vite

🛠 Starter kit of Nette used with Vite
17 stars 5 forks source link

about importmaps instead vite #3

Closed alnux closed 1 year ago

alnux commented 1 year ago

Hello @lubomirblazekcz , I was able to read the article you wrote regarding nette and vite here, how you also talk about hotwire turbo and stimulous and I was able to do the integration in a basic way but with just importmaps, but I have problems with Tracy, because turbo loads the scripts on the first page loaded and Tracy doesn't load again when the browser loads another page, like turbo already loads Tracy the first time it doesn't load on page change. I implemented nette's tutorial on creating a blog, and it works wonderfully, but seeing the generated code Tracy's script loads outside of HTML, it only loads once and the next time an error appears in Tracy's console.

?_tracy_bar=js&v=2.10.2&XDEBUG_SESSION_STOP=1:36 Uncaught TypeError: Cannot read properties of null (reading 'Tracy') at new Panel (?_tracy_bar=js&v=2.10.2&XDEBUG_SESSION_STOP=1:36:31) at ?_tracy_bar=js&v=2.10.2&XDEBUG_SESSION_STOP=1:455:30 at NodeList.forEach (<anonymous>) at Debug.loadAjax (?_tracy_bar=js&v=2.10.2&XDEBUG_SESSION_STOP=1:453:48) at ?_tracy_bar=content-ajax.7cfcbf8d5c_1&XDEBUG_SESSION_STOP=1&v=0.02912595203643198:1:13

maybe when loading tracy inside at the end of the body this error won't occur and tracy can work without problem, if I'm right how can I do this?? Maybe you, knowing better about the subject, can enlighten me about it.

Here the Turbo with importmaps

public/assets/js/app.js

import 'libs';

public/assets/js/libs/index.js

import 'libs/turbo';

public/assets/js/libs/turbo.js

import * as Turbo from '@hotwired/turbo';
export default Turbo;

app/presenters/templates/@layout.latte

<!DOCTYPE html>
<html>
    <head>
        <title>{ifset title}{include title|stripHtml} | {/ifset}Nette Web</title>
        <!-- Scripts -->
        <script type="importmap" data-turbo-track="reload">
        {
        "imports": {
            "@hotwired/turbo": "https://ga.jspm.io/npm:@hotwired/turbo@7.3.0/dist/turbo.es2017-esm.js",
            "app": "https://nette.test/assets/js/app.js",
            "libs": "https://nette.test/assets/js/libs/index.js",
            "libs/turbo": "https://nette.test/assets/js/libs/turbo.js"
            }
        }
        </script>
        <link rel="modulepreload" href="https://nette.test/assets/js/app.js"/>
        <link rel="modulepreload" href="https://nette.test/assets/js/libs/index.js"/>
        <link rel="modulepreload" href="https://nette.test/assets/js/libs/turbo.js"/>
        <script async src="https://ga.jspm.io/npm:es-module-shims@1.7.2/dist/es-module-shims.js" data-turbo-track="reload"> </script>
        <script type="module" data-turbo-track="reload">import 'app';</script>
    </head>

<body>
....
....

</body>
</html>

If you see here the tracy is load after but it is still inside document root, how to makes works tracy in armony with turbo

...........
.........
.......
</body>
  </html>

<!-- Tracy Debug Bar -->

  <script src="/?_tracy_bar=js&amp;v=2.10.2&amp;XDEBUG_SESSION_STOP=1" data-id="a7b0572866"></script>
  |<script>

<!-- Tracy Debug Bar -->
<script src="[/?_tracy_bar=js&amp;v=2.10.2&amp;XDEBUG_SESSION_STOP=1](https://nette.test/?_tracy_bar=js&v=2.10.2&XDEBUG_SESSION_STOP=1)" data-id="a7b0572866"></script>
<script>
Tracy.Debug.init( .......
</script>
lubomirblazekcz commented 1 year ago

I'm afraid I can't help you with this as I don't really have much experience with Turbo myself. But as far I can tell from your examples, this might be more of a question for https://github.com/nette/tracy

We're using tracy with https://swup.js.org/ and tracy loads only once and after that works without a problem, so I don't know where might the issue be with Turbo