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

Initial component upgrade cannot be prevented. #4780

Closed
AlexanderOtavka opened this issue Sep 23, 2016 · 6 comments
Closed

Initial component upgrade cannot be prevented. #4780

AlexanderOtavka opened this issue Sep 23, 2016 · 6 comments

Comments

@AlexanderOtavka
Copy link
Contributor

Initial component registration happens on page load and cannot be deferred or canceled. This is a problem for me because I am working with the shadydom polyfill and the initial upgrade prevents slot content from working properly. This may just be a bug with shadydom, however a developer could conceivably want to defer registration for other reasons, especially if another framework isn't playing nice.

I propose the following solution.

Before loading the mdl javascript, the developer can set window.componentHandlerConfig = { preventAutoUpgrade: true };. When componentHandler is created, the preventAutoUpgrade property is copied to a componentHandler.config object, but defaults to false. If preventAutoUpgrade is true at page load time, the initial componentHandler.upgradeAllRegistered() call will not happen.

I'm going to go ahead and implement this on my fork, but I'll make a PR too. Any suggestions on how to do this better are welcome.

@Garbee
Copy link
Collaborator

Garbee commented Sep 23, 2016

I'd rather we avoid introducing another global variable just for CH config. Why not add in a componentUpgrading event before the initialization happens? Which can be canceled to skip over initialization.

@AlexanderOtavka
Copy link
Contributor Author

Ok, should I have the window fire that event on load? I thought event.stopPropogation() only worked to prevent an event from bubbling up the dom. Maybe the body or the rootElement should fire the componentUpgrading event?

@Garbee
Copy link
Collaborator

Garbee commented Sep 23, 2016

Not one window event. But, in the component handler as the component is upgrading. Fire it against the node itself which can be listened for and canceled. This provides an explicit way to stop initialization on any given component instance at any point in time instead of just during the initial page load.

@AlexanderOtavka
Copy link
Contributor Author

Ah, smart. I've done a little more reading, and it seems the Element.dispatchEvent() will return false if the event is canceled. I'll update my PR.

@Garbee
Copy link
Collaborator

Garbee commented Sep 23, 2016

You should use defaultPrevented MDN instead of checking for a cancel. That way it is clear and direct as to what will cause a bail and what won't.

@AlexanderOtavka
Copy link
Contributor Author

AlexanderOtavka commented Sep 23, 2016

Ok, sounds good. I have updated PR #4781.

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

No branches or pull requests

2 participants