Skip to content
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

run onMount in connectedCallback for custom elements #4527

Closed

Conversation

hontas
Copy link
Contributor

@hontas hontas commented Mar 8, 2020

relates to #1152 and #4522
resolves #2227

When compiling to custom element the onMount hook get called before props have initialized which causes confusion.

Here's how to access props in onMount now:

import { onMount, tick } from 'svelte';

onMount(() => {
  tick().then(() => {
    // props are available
  });
});

This PR changes this to be simpler and map better to connected callback.

import { onMount } from 'svelte';

onMount(() => {
    // props are available
});

* 'master' of https://github.com/sveltejs/svelte: (137 commits)
  -> v3.19.2
  fix lazy code breaks in build
  fit bitmask overflow initial dirty value in 'if' blocks (sveltejs#4507)
  add dev runtime warning for unknown slot names (sveltejs#4501)
  fix render fallback slot content due to whitespace (sveltejs#4500)
  docs: describe falsy and nullish attribute behavior (sveltejs#4498)
  in spread, distinguish never-updating and always-updating props (sveltejs#4487)
  chore: more specific typings, and add README note about Yarn (sveltejs#4483)
  update changelog
  check for unknown props even if component doesn't have writable props (sveltejs#4454)
  Bump codecov from 3.5.0 to 3.6.5 (sveltejs#4433)
  fix bitmask overflow for slot (sveltejs#4485)
  mark module variables as mutated or reassigned (sveltejs#4469)
  docs: referenced_from_script var value (sveltejs#4486)
  docs: clarify default prop behaviour (sveltejs#4460)
  site: turn fancybutton into custombutton (sveltejs#4476)
  update changelog
  exclude global variables from $capture_state (sveltejs#4475)
  -> v3.19.1
  don't treat $$-names as stores during invalidation (sveltejs#4453)
  ...
@hontas
Copy link
Contributor Author

hontas commented Mar 9, 2020

Is there a way to re-trigger the checks w/o pushing? Seem to be an error not related to the PR itself.

@nolanlawson
Copy link
Contributor

+1 to this. Right now I'm using the tick() workaround, but it's awkward because my code has to handle the non-initialized state as well as the initialized state. (I.e. have to check that lots of props are non-null, when really they should never be null.)

@Truffula
Copy link

#5139 should fix the onMount issue as well as making initial props available on initialization (before onMount) — i.e. #2227. I don't think it affects the onDestroy issues.

@hontas
Copy link
Contributor Author

hontas commented Jul 17, 2020

Fix moved to #4522

@hontas hontas closed this Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prop initialization in web/standalone components
3 participants