-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Comments
I'd rather we avoid introducing another global variable just for CH config. Why not add in a |
Ok, should I have the window fire that event on load? I thought |
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. |
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. |
You should use |
Ok, sounds good. I have updated PR #4781. |
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 };
. WhencomponentHandler
is created, thepreventAutoUpgrade
property is copied to acomponentHandler.config
object, but defaults to false. IfpreventAutoUpgrade
is true at page load time, the initialcomponentHandler.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.
The text was updated successfully, but these errors were encountered: