Skip to content

Conversation

@MarkoMlakar
Copy link

This PR

  • Remove redundant loop for updating the before hook contexts
  • Add simple test case to make sure the same object reference is being updated

Related Issues

#1236

Notes

The accumulated evaluation context object is shared with all the hooks (same object reference). This makes the inner for loop for updating the contexts redundant

How to test

npm run test

- Remove redundant loop for updating the hook contexts
- Add simple test case to make sure the same object reference is being updated

Signed-off-by: Marko Mlakar <markomlakar2@gmail.com>
Copy link
Member

@aepfli aepfli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you this looks good to me - but i am by far not a js expert, maybe somebody else can have a look at this

const hookContext = hookContexts[hookContextIndex];

// Update the context on the stable hook context object
Object.assign(hookContext.context, accumulatedContext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove this line, the accumulatedContext is not available in the beforeHook on the next line.

Copy link
Author

@MarkoMlakar MarkoMlakar Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @guidobrei you are correct. I have updated the PR

Signed-off-by: markomlakar <marko.mlakar@dynatrace.com>
* Reverted the purposed changes to ensure the before hook gets the accumulated hook context
* Replaced the for loop with a single shared object update

Signed-off-by: MarkoMlakar <marko.mlakar@dynatrace.com>
Object.assign(accumulatedContext, hookResult);

for (let i = 0; i < hooks.length; i++) {
Object.assign(hookContexts[hookContextIndex].context, accumulatedContext);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hookContext.context is a shared object. All the hooks recieve and operate on the same context object, making this for loop redundant

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? from the method signature it could be different contexts.

@MarkoMlakar MarkoMlakar marked this pull request as ready for review December 11, 2025 12:06
@MarkoMlakar MarkoMlakar requested review from a team as code owners December 11, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants