Closed s00500 closed 4 months ago
I unfortunatly also just realized that I cant use
this.ws = new WebSocket(this.url, this.protocols);
at all....
neither window.WebSocket(this.url, this.protocols);
@s00500 - I assume you're getting a build error like ReferenceError: ReconnectingWebSocket is not defined
, is that correct?
The build process creates both the interactive clientside JS (which has access to browser objects like window
) and HTML fallbacks (which don't have access to the browser / runtime JS). If I have something that needs to be run clientside only, I typically wrap it in onMount so it's ignored by the SSR part of the build that creates the HTML.
Can you try putting the clientside logic inside onMount and let me know if that help? For example:
<script>
import { ReconnectingWebSocket } from "../scripts/reconnecting-ws.js";
import { onMount } from 'svelte';
let ws;
onMount(() => {
ws = new ReconnectingWebSocket("ws://localhost:3", []);
});
</script>
Hey @jimafisk, that nailed it! Thanks a lot !!! (would ofc be awesome to have a error that can be traced easier ;-) )
Awesome, I'm glad it worked @s00500, thanks for following up!
I am trying to create a class in a .js file and import it into one of my components. But that seems to not work... any ideas ? or is this not intended in the context of plenti right now ?
I did take a quick look at the build package but did not go through all the regex 🙈
Otherwise this tool is pretty cool!!!! Love it so far
Code:
Component:
Imported file