Closed anicolao closed 1 year ago
Deferring new TwistyPlayer()
until onMount
made the issue go away, so this can be closed if that is WAI.
Perhaps it is not safe to call
new TwistyPlayer()
before there is a DOM?
That depends, but it's certainly possible that SSR code is making assumptions that are incompatible with our use of the DOM. We could avoid .attachShadow()
until .connectedCallback()
, but I don't think that's a great workaround.
Do you have a self-contained repro I could test against?
Not really, though the pasted file could be thinned out to not contain the stickering pretty quickly. SSR is disbabled in my application, but the JS inside a svelte component isn't in a normal context until onMount
is called. I am not at all familiar with the initialization order as it basically never bites me.
Unfortunately, I'm not able to reproduce this at all. The following works as expected:
<script lang="ts">
import { TwistyPlayer } from "cubing/twisty";
import { onMount } from 'svelte';
const twistyPlayer = new TwistyPlayer();
onMount(async () => {
document.body.appendChild(twistyPlayer);
});
</script>
I would need a more specific repro to debug this.
Hmm. I may have made some terrible error and enabled SSR in some way I don't understand. Svelte has been great but has also proven to be a bit of a moving target, I'll see if I can narrow it down ... at the moment, nothing is serving.
I wound up in some sort of npm versioning purgatory and after much penance, repeated npm update
commands and npm obsolete
commands, eventually exorcized whatever version mismatch was making svelte unhappy. When all that was done, this problem no longer reproduced...
I wound up in some sort of npm versioning purgatory and after much penance, repeated
npm update
commands andnpm obsolete
commands, eventually exorcized whatever version mismatch was making svelte unhappy. When all that was done, this problem no longer reproduced...
Glad to see it you managed to resolve it! 😄
Steps to reproduce the issue
I recently refactored my cubing site with the intention of making it possible for users to share solves without everyone being authenticated.
The svelte component I wrote doesn't work in this new context; it only works if I first load the site, and later load the component. I really don't have much of a clue as to what the race condition is and am hoping for some pointers to debug it.
Observed behaviour
The error displayed to the user instead of the web page is a 500 return code with the text:
The code that triggers it is in a file called
Cube.svelte
that looks like this:Perhaps it is not safe to call
new TwistyPlayer()
before there is a DOM?Expected behaviour
I would have expected the
TwistyPlayer
class to be instantiable outside of a browser's javascript execution environment, but this might be wrong.Environment
MacOS Chrome
🖼 Screenshots
No response
Additional info
No response