[GH-ISSUE #105] Listening to value data event duplicates parts of mutated event ref path #60

Closed
opened 2026-05-23 08:28:43 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @Bubz43 on GitHub (May 19, 2022).
Original GitHub issue: https://github.com/appy-one/acebase/issues/105

Originally assigned to: @appy-one on GitHub.

const wait = () => new Promise((resolve) => setTimeout(resolve, 0));

let path = '';
db.ref('recipes').on('mutated', (mutated) => {
  path = mutated.ref.path;
});

const ref = await db.ref('recipes').push({ name: 'cake' });
await wait();

expect(path).toBe('recipes');

await ref.update({ name: 'Cake' });
await wait();

expect(path).toBe(`recipes/${ref.key}/name`);

// Comment out value listener and test passes
db.ref('recipes').on('value', () => {});

await ref.update({ name: 'Bread' });
await wait();

expect(path).toBe(`recipes/${ref.key}/name`);

If listening to the value event the path will be something like recipes/recipe_id/recipe_id/name. The target in mutations event also suffers the same problem.
As far as I can tell its just the value event that does this. Everything else, including notify_value, doesn't cause problems.

Also on an unrelated note, but probably not worth opening a second issue for, is the forEach and child methods of MutationsDataSnapshot both call this.val() without passing false, so it warns you to use the methods you already are using.

Originally created by @Bubz43 on GitHub (May 19, 2022). Original GitHub issue: https://github.com/appy-one/acebase/issues/105 Originally assigned to: @appy-one on GitHub. ```js const wait = () => new Promise((resolve) => setTimeout(resolve, 0)); let path = ''; db.ref('recipes').on('mutated', (mutated) => { path = mutated.ref.path; }); const ref = await db.ref('recipes').push({ name: 'cake' }); await wait(); expect(path).toBe('recipes'); await ref.update({ name: 'Cake' }); await wait(); expect(path).toBe(`recipes/${ref.key}/name`); // Comment out value listener and test passes db.ref('recipes').on('value', () => {}); await ref.update({ name: 'Bread' }); await wait(); expect(path).toBe(`recipes/${ref.key}/name`); ``` If listening to the `value` event the path will be something like `recipes/recipe_id/recipe_id/name`. The target in `mutations` event also suffers the same problem. As far as I can tell its just the `value` event that does this. Everything else, including `notify_value`, doesn't cause problems. Also on an unrelated note, but probably not worth opening a second issue for, is the `forEach` and `child` methods of `MutationsDataSnapshot` both call `this.val()` without passing false, so it warns you to use the methods you already are using.
gitea-mirror 2026-05-23 08:28:43 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@appy-one commented on GitHub (May 19, 2022):

Thanks for your detailed report, I'll dive into this!

<!-- gh-comment-id:1132261230 --> @appy-one commented on GitHub (May 19, 2022): Thanks for your detailed report, I'll dive into this!
Author
Owner

@appy-one commented on GitHub (May 20, 2022):

Fixed it, published new version 1.19.2. Many thanks for reporting this!

Spread the word contribute Sponsor AceBase

<!-- gh-comment-id:1132781866 --> @appy-one commented on GitHub (May 20, 2022): Fixed it, published new version 1.19.2. Many thanks for reporting this! [![Spread the word](https://user-images.githubusercontent.com/26569719/169265089-3d593555-e1ad-4390-986b-877ac2c38a47.svg)](https://twitter.com/intent/tweet?button=&url=https://github.com/appy-one/acebase&text=I'm+using+@AcebaseRealtime+in+my+project+to+make+my+life+easier!&button=) [![contribute](https://user-images.githubusercontent.com/26569719/169265318-30c4c6a5-7c89-46a0-a7a2-ef433a8192f4.svg)](https://github.com/appy-one/acebase#contributing) [![Sponsor AceBase](https://user-images.githubusercontent.com/26569719/168233053-8e56b243-4140-40ab-9a30-4cb3cc149bfe.svg)](https://github.com/sponsors/appy-one)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#60
No description provided.