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

mdcFoundation should be initialised before firstUpdated #308

Closed
elyobo opened this issue Jul 23, 2019 · 3 comments · Fixed by #356
Closed

mdcFoundation should be initialised before firstUpdated #308

elyobo opened this issue Jul 23, 2019 · 3 comments · Fixed by #356

Comments

@elyobo
Copy link

elyobo commented Jul 23, 2019

Delaying mdcFoundation instantiation until firstUpdated (see base-element) means that any other methods which rely on the foundation (e.g. opening a snackbar) will fail.

Is there a reason it's deferred instead of simply running in the constructor?

@Westbrook
Copy link

Being LitElement renders async waiting for firstUpdated (which is triggered via code paths initiated in the constructor) is the way to ensure component DOM is available when mdcFoundation is run against the element. If the element didn't wait and then tried to open a snackbar before firstUpdated it wouldn't really be there to open.

You can see the code path from constructor to initialize to _requestUpdate to _requestUpdate to _enqueueUpdate to performUpdate to firstUpdated in https://github.com/Polymer/lit-element/blob/master/src/lib/updating-element.ts to better understand the piping here.

@elyobo
Copy link
Author

elyobo commented Jul 23, 2019

Thanks for the explanation and pointer to the relevant code; odd that the initialisation is async when DOM manipulation is sync.

Perhaps attempts to perform actions before a component is ready should queue actions and then handle them on firstUpdate when it's safe to do so instead? I'm not familiar with the code at all yet, so not sure whether that makes practical sense or where it should go (e.g. instantiate mdc foundation in constructor instead and have it handle queueing, then flush the queue on firstUpdate maybe?)

@elyobo
Copy link
Author

elyobo commented Aug 12, 2019

Thanks @azakus!

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 a pull request may close this issue.

2 participants