FIX: Prevent `PreloadStore` from calling the finder when value is falsy (#14899)

FIX: Prevent PreloadStore from calling the finder when value is falsy (#14899)

diff --git a/app/assets/javascripts/discourse/app/lib/preload-store.js b/app/assets/javascripts/discourse/app/lib/preload-store.js
index 9fe7ca3..3562b1d 100644
--- a/app/assets/javascripts/discourse/app/lib/preload-store.js
+++ b/app/assets/javascripts/discourse/app/lib/preload-store.js
@@ -3,10 +3,10 @@
 import { Promise } from "rsvp";
 
 export default {
-  data: {},
+  data: new Map(),
 
   store(key, value) {
-    this.data[key] = value;
+    this.data.set(key, value);
   },
 
   /**
@@ -16,9 +16,9 @@ export default {
     So, for example, you can't load a preloaded topic more than once.
   **/
   getAndRemove(key, finder) {
-    if (this.data[key]) {
-      let promise = Promise.resolve(this.data[key]);
-      delete this.data[key];
+    if (this.data.has(key)) {
+      let promise = Promise.resolve(this.data.get(key));
+      this.data.delete(key);
       return promise;
     }
 
@@ -41,16 +41,14 @@ export default {
   },
 
   get(key) {
-    return this.data[key];
+    return this.data.get(key);
   },
 
   remove(key) {
-    if (this.data[key]) {
-      delete this.data[key];
-    }
+    this.data.delete(key);
   },
 
   reset() {
-    this.data = {};
+    this.data = new Map();
   },
 };
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/preload-store-test.js b/app/assets/javascripts/discourse/tests/unit/lib/preload-store-test.js
index 089ef19..ca060af 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/preload-store-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/preload-store-test.js
@@ -54,4 +54,12 @@ module("Unit | Utility | preload-store", function (hooks) {
     const result = await PreloadStore.getAndRemove("bane");
     assert.strictEqual(result, "evil");
   });
+
+  test("returns falsy values without calling finder", async function (assert) {
+    PreloadStore.store("falsy", false);
+    const result = await PreloadStore.getAndRemove("falsy", () =>
+      assert.ok(false)
+    );
+    assert.strictEqual(result, false);
+  });
 });

GitHub sha: 97aa56bdc326ae7d67bb6060d95b5637c033d9c4

This commit appears in #14899 which was approved by nbianca. It was merged by CvX.