LoginSignup
8
3

More than 5 years have passed since last update.

Firebase SDKのReleaseNotesはこまめにチェックしよう!

Last updated at Posted at 2016-12-08

はじめに

どうも、はたです。
空きがあるのはなにか寂しいので、臨時で埋めます。

今回は掲題の通り、SDKの話ですが、
Firebase JavaScript SDKですので、ご了承ください。

Release Notes見てますか?

ここですねはい。
結構頻繁に更新されています。
FIXED、CHANGED、DEPRECTEDなどあって、重量なバグフィックスとかもされたりしてます。
Firebaseを使い始めた当初、SDKの更新はあまり気にしていなかったのですが、
あることがきっかけでSDKの更新をチェックするようになりました。

Firebase SDK(js) 3.0.0で起きた問題

SDKのバージョン3.0.0を使っている時、下記の問題に遭遇しました。

transactionの次にupdateを書いた場合

db.child('/test/user1/count').transaction(function (currentValue) {
    return currentValue ? currentValue - 1 : 0;
}).catch(function (error) {
    console.log(error)
});

var updates = {}
updates['/test2/user1'] = null;
updates['/test2/user2'] = null;
db.update(updates).catch(function (error) {
    console.log(error)
});

この流れで処理すると・・・

Error: set
    at Error (native)
    at ji (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:466:437)
    at $h (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:464:351)
    at https://www.gstatic.com/firebasejs/3.3.0/firebase.js:464:286
    at https://www.gstatic.com/firebasejs/3.3.0/firebase.js:431:167
    at nh.h.wd (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:432:104)
    at af.wd (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:335:364)
    at vd.hg (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:333:280)
    at yd (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:286:464)
    at WebSocket.La.onmessage (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:285:245)

エラーになるんです。

updateの次にtransactionを書いた場合

var updates = {}
updates['/test2/user1'] = null;
updates['/test2/user2'] = null;
db.update(updates).catch(function (error) {
    console.log(error)
});

db.child('/test/user1/count').transaction(function (currentValue) {
    return currentValue ? currentValue - 1 : 0;
}).catch(function (error) {
    console.log(error)
});

これはエラーになりません。
dbのパスが完全に違えばtransaction上の他更新パスへの影響はないと勝手に認識していたので軽い衝撃でした。

それっぽい困っている人もいた
http://stackoverflow.com/questions/30147645/firebase-transaction-error-set

SDKのバグだった

原因はわからず、ふとFirebase SDK(js)のRelease Notesを見てみると
気になる記述がありました。

Version 3.4.1 - September 27, 2016

Release Notes

Realtime Database
FIXED Use of the update() method now only cancels transactions that are directly included in the updated paths (not transactions in adjacent paths). For example, an update at /move for a child node walk will cancel transactions at /, /move, and /move/walk and in any child nodes under /move/walk. But, it will no longer cancel transactions at sibling nodes, such as /move/run.

なるほど、それっぽい。
ということで3.0.0から3.4.1にSDKを更新したところ、エラーの現象は直ったのです!

おわりに

Release Notesは頻繁にチェックしよう!ってことでした。
当たり前ですけどね・・・w
JavaScriptにしかり、iOS、Androidにしかり、利用しているSDKのバージョンアップをきちんとチェックしないといけないと改めて感じた出来事でした。

8
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3