DavidWells / DavidWells/analytics

Removing properties from payload.properties or payload.traits in namespaced hooks doesn't propagate to downstream hooks

Open
#26 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.7k
Forks
267
PR merge metrics
No merged PRs in 30d

Description

Current behavior:
If I have 2 plugins with e.g. a track hook, and one plugin defines a namespaced hook to run before the other plugin (track:pluginB in the example below), then when I try to remove a property from payload.property object in the upstream plugin, this change is not propagated to the downstream plugin (see example below).

This is unexpected behavior, as other changes seem to be propagated correctly.

Desired behavior:
If I remove properties in the upstream plugin, the change should be propagated to the downstream plugin and the property should not be defined on the object there.

import { omitBy, isNil } from "lodash";

// plugin A
{
  name: "pluginA",
  "track:pluginB": ({ payload }) {
    // Returns payload with null or undefined values removed from
    // payload.properties
    return {
      ...payload,
      properties: {
        ...omitBy(payload.properties, isNil)
        test: true
    };
  }
  ...
};

// plugin B
{
  name: "pluginB",
  config: { payload },
  track:
    // The printed properties object includes `test: true`, so the payload
    // was clearly passed through pluginA["track:pluginB"], but the object
    // also still includes null and undefined values, although the `omitBy`
    // function removed them.
    console.log(payload.properties);
    return payload;
  ...,
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the namespaced hook dispatch and payload propagation logic used by track:pluginB, then reproduce the issue with the two-plugin example in the report. Verify how payload.properties is copied or merged between hooks. Done means properties removed by the upstream hook remain absent in the downstream plugin, with a regression test covering null and undefined values.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.