Bug
When the user inputs text to MatInput or selects an option in MatSelect, the placeholder should disappear (as defined by the MAT_LABEL_GLOBAL_OPTIONS) and form validations should activate.
The behavior works as expected on development builds. However when bundled with "ng build -prod" we get the following outcomes:
These behaviors also affect form validations.
build an app with the -prod flag
when tested on a demo app with the following package.json configuration, we get expected behavior
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/cdk": "^2.0.0-beta.8",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/material": "^2.0.0-beta.8",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"material-design-icons": "^3.0.1",
"rxjs": "^5.4.1",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.3.1",
"@angular/compiler-cli": "^4.0.0",
"@angular/language-service": "^4.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~8.0.17",
"codelyzer": "~3.1.2",
"firebase-tools": "^3.9.1",
"jasmine-core": "~2.7.0",
"jasmine-spec-reporter": "~4.2.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.3.0",
"tslint": "~5.6.0",
"typescript": "~2.4.2"
}
however when updated to Angular v.5 packages, the demo app also fails to produce expected behavior.
It looks like your Material version is pretty old. Can you try using the latest version?
my apologies, I should've posted the configuration that fails instead. The above configuration was used to test whether an app using an older version behaves differently or not. The failing configuration is:
"dependencies": {
"@angular/animations": "^5.1.2",
"@angular/cdk": "^5.0.2",
"@angular/common": "^5.1.2",
"@angular/compiler": "^5.1.2",
"@angular/core": "^5.1.2",
"@angular/forms": "^5.1.2",
"@angular/http": "^5.1.2",
"@angular/material": "^5.0.2",
"@angular/platform-browser": "^5.1.2",
"@angular/platform-browser-dynamic": "^5.1.2",
"@angular/router": "^5.1.2",
"angular2-text-mask": "^8.0.4",
"core-js": "^2.5.3",
"font-awesome": "^4.7.0",
"jquery": "^3.2.1",
"rxjs": "^5.5.6",
"text-mask-addons": "^3.7.1",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.6.2",
"@angular/compiler-cli": "^5.1.2",
"@angular/language-service": "^5.1.2",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.95",
"@types/jquery": "^3.2.17",
"codelyzer": "^4.0.2",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
When you updated (2.0.0-beta.8 => 5.0.2) did you follow the 3 steps below before npm install it?
md with mat prefixall of the above steps were done multiple times to ensure that nothing slips by. this example app was run just to see whether it was a local issue or was consistent across different apps as well. the original app that I had problems with was built with āng newā on the angular-cli 1.6.1
the most important issue is that, whilst the following commands produce the desired outcome on browsers:
I have downloaded the official Angular Material template provided here and ran the app both with and without -prod flag
[ng serve/build]
[ng serve/build -prod]
Same issue occurred on 3 different machines, tested on 2 different browsers, both with regular and incognito modes
Ok... so the problem is easily reproducible by following the steps you've pointed out (create a new project and build it to production). I can give it a try, maybe tomorrow.
The machines you used... All of them run Mac OS + SAFARI?
2 machines we have tested on are Mac OS, one tested with safari + chrome, other tested with firefox + safari
the other machine is our deployment platform, Ubuntu 16.04 hosted on Amazon AWS.
Just to make sure that this might be an issue with the v5 release, I have checked some example apps built with Material, and it seems that the placeholder issue is there as well.
For example, this is a test app that uses Angular + Material v2 and as you can see the placeholder restores to its original location when the input is empty.
This here is one built with v5 and if you try to use the searchbar on top right, you should be experiencing the same issue that we are experiencing and the autocomplete shouldn't work as well as a floating placeholder when input is left blank.
I confirm I could see the problem in the links you've posted.
@oytuneyucel, I could reproduce it in a test app, available in heroku. In the images below you can notice that not just the label stops working, but also the interpolation (see the gifs, just beneath the inputs). It doesn't seems to be related just to material... maybe @angular/cli's build-optimizer flag has something to do with it. I noticed the problem using Chrome and Firefox (Windows 10)


If it helps, the repo for the test app above: https://github.com/julianobrasil/material2-test
Some time after you push to master (it's not protected - anyone can push), the app can be viewed from https://angular-julianobrasil.herokuapp.com/ (it's a free heroku account so it goes to sleep after 30 min idle and takes some time to wake up after someone tries do access it for the first time)
cc: @filipesilva
@oytuneyucel, this @cuiliang's suggestion (https://github.com/angular/angular-cli/issues/8997#issuecomment-353957698) worked partially for me (in my tiny test project)
ng build --aot --build-optimizer true --output-hashing all --extract-css true --name
d-chunks false --sourcemaps false --environment prod
But the chunks size increased a lot šø - cannot use it in production
after a few verbose builds, I think I have pinpointed the operation that causes the problem yet donāt have a solution.
after ejecting the app from the cli, you can go to webpack configuration file and set UglifierJsPluginās mangle option to false. building the app with this config restores text input functionality albeit making it not so pleasant for a prod build.
I have read in couple issues submitted to angular repo that the UglifyJS mangler has been problematic in the past but didnāt have the chance to analyze how these two can be related.
on mobile now, will post with references when back on my computer
@julianobrasil thought I tried all possible combination of flags, but will give it a try again
@oytuneyucel, @trotyl suggested the same in angular-cli repo: https://github.com/angular/angular-cli/issues/8997#issuecomment-353962335
I am also experiencing the same issue. All the forms in application are affected. Form validations have stopped working. Solution needed ASAP. It is working fine on local but not on prod. Have a demo in couple of hours.
It's being tracked at @angular/cli repo: https://github.com/angular/angular-cli/issues/8997
@oytuneyucel, @kd2801:
As suggested by @filipesilva (the problem seems to be related to [email protected]):
So, temporarily:
1 - add [email protected] to dependencies array in package.json
2 - delete package-lock.json, node_modules and dist
3 - npm install
Or, to linux users:
npm i [email protected] --save-exact && rm -rf package-lock.json node_modules && npm i && npm ls uglify-es
@julianobrasil I can confirm that @filipesilva 's solution does work for our project and uglify-es 3.3.0 indeed causes the problem with the production build
+1. Angular forms didn't work at all in production builds when MatInputModule is imported. Using [email protected] instead of 3.3.2 fixed the problem
+1. Now, all forms builds in production mode, didn't work! :(
@monoflash, have you tried what's pointed out in https://github.com/angular/material2/issues/9120#issuecomment-353972441 ?
Now I tried to do what is stated in the comments again.
It worked.
Apparently the cache was not cleared at the first attempts.
Very bad bug! It took a long time to find the problem... :(
We just released @angular/[email protected] which works around a problem in uglify that causes this. See angular/angular-cli#8997 for more information.
Cool! Thank you guys! Saved my day!!!
Closing since this has been sorted out by the CLI team.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
@oytuneyucel, @kd2801:
As suggested by @filipesilva (the problem seems to be related to
[email protected]):So, temporarily:
1 - add
[email protected]to dependencies array in package.json2 - delete package-lock.json, node_modules and dist
3 - npm install
Or, to linux users: