-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Current component should (probably?) not be available inside onMount #4259
Comments
I asked the original question on discord. The case I had was on https://github.com/dopry/svelte-auth0/blob/b11d46db898c2fea0015ae7ce0e56d7a6e9d1ab2/src/components/Auth0Context.svelte#L41 if I replace You can test by running |
Something else that just came up on chat is someone trying to call |
Confirmed with Rich that this is not an intended feature, and that if it is easy to prevent this then we should. |
Starting with documentation may be a good idea, if the compile time errors will take a moment to implement. My poor understanding is that OnMount is basically running at construction time and that the component isn't in a stable state for modification. And that rather than interacting directly with the component I should be interacting with in-scope variables that are used by the component instead. |
The above component now throws an error at runtime in 3.25.0. |
@Conduitry - Do you remember this discussion from a year and a half ago? I ask because I'm trying to fix #6919 with #6920, and making the current component explicitly unavailable during Thing is, this is the example code from the <script>
import { onMount } from 'svelte';
let canvasElement;
onMount(() => {
const ctx = canvasElement.getContext('2d');
drawStuff(ctx);
});
</script>
<canvas bind:this={canvasElement}></canvas> Those docs certainly imply that If you have any memory of the conversation with Rich that you mentioned on Feb 4, 2020 — or if you have any way to retrieve chat logs of that conversation from over 18 months ago — I'd love to understand the expected state of the component during |
Describe the bug
Things that internally use
get_current_component()
should probably fail when they are called from anonMount
callback.Logs
None.
To Reproduce
Expected behavior
I'd expect this to crash, but it doesn't. There is an exception if you use
setTimeout
instead ofonMount
.Stacktraces
n/a
Information about your Svelte project:
Severity
I'm not sure. I'm not actually positive this is a bug, but it feels like it. I don't think we want people to be able to call other lifecycle hooks or access the context within
onMount
.Additional context
Came up in chat by way of a question about calling
setContext
in a component and then callinggetContext
during that component'sonMount
callback. It feels like this shouldn't actually be allowed.The text was updated successfully, but these errors were encountered: