Given long polling is enabled, saving strings with an accent (and other non-standard chars) to the realtime database, is throwing an encoding issue.
I am not sure if it is a problem with uglifyJs, but one person found out uglifyJs was causing this same issue. But in my example, I am using the minified version provided by Firebase, I am not using uglifyJs.
https://github.com/firebase/firebase-js-sdk/issues/1356
https://github.com/mishoo/UglifyJS2/issues/3278
You can see the issue happening here:
https://codepen.io/glauberramos/pen/KOmzRR
firebase.initializeApp(firebaseConfig);
firebase.database.INTERNAL.forceLongPolling();
firebase.database().ref('test/').set('茅帽氓')
I found a few problems with this issue:
I can reproduce the issue, here: https://jsbin.com/nasuwem/edit?js,console
firebase.database.INTERNAL.forceLongPolling();
ref.set("膶esk谩 republika")
.then(() => console.log("Written") )
.catch((e) => console.error(e))
ref.on("value", (snapshot) => { console.log(snapshot.val()); })
Running this logs:
"膶esk谩 republika"
"锟斤拷esk锟斤拷 republika"
"Written"
So the first line is the local event, the second line the value from the server, where it is indeed also broken (see json).
Removing the firebase.database.INTERNAL.forceLongPolling() fixes the problem, ruling out issues in the application code.
@glauberramos Thanks for filing this issue. Unfortunately, we are internally using UglifyJs to build our sources, which I believe introduces this problem. Since we have gotten a number of user reports lately, I will get this prioritized again and see if we can find a workaround.
Thanks, @schmidt-sebastian, it will be very nice if you could fix this issue because it is currently affecting users of my product from many countries. From my understanding, it is a critical bug because people cannot write text normally.
If you use uglifyJs version 3.4.8 this issue should not happen. But you probably could test with the latest version as well, I believe the version with issues is 3.4.9.
Is there any non minified version of firebase available?
@glauberramos If you use our NPM packages in your build, you can use the non-minified versions (https://www.npmjs.com/package/firebase)
Thanks @schmidt-sebastian
Where are the non minified version of firebase on NPM package? All files available at root are minified. I am looking at "firebase" module.
@glauberramos We may have been wrong in regards to how the NPM packages are published.
But we have good news as well: https://github.com/firebase/firebase-js-sdk/pull/2039 will fix this issue as the underlying problem has been fixed in UglifyJs.
Most helpful comment
@glauberramos We may have been wrong in regards to how the NPM packages are published.
But we have good news as well: https://github.com/firebase/firebase-js-sdk/pull/2039 will fix this issue as the underlying problem has been fixed in UglifyJs.