Reviewed & tested by the community
Project:
Context
Version:
5.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
1 Apr 2025 at 02:23 UTC
Updated:
8 Apr 2026 at 07:21 UTC
Jump to comment: Most recent
Comments
Comment #3
loze commentedIm not sure if this is the correct approach, but it does fix the problem for me.
Im keying the activeContexts array by context id which makes sure any context is only set once.
Comment #4
loze commentedI would have thought the $this->contextConditionsEvaluated variable takes care of this but apparently when both these reactions are used the value is somehow getting reset? I tried figuring that out but not sure whats going on there.
Comment #5
benstallings commentedClaude Code says:
Three things happening in the single-line change:
1. Keys the array by context ID — $this->activeContexts[$context->id()] = $context instead of $this->activeContexts[] = $context. This prevents the same context from appearing multiple times.
2. Skips already-evaluated contexts — empty($this->activeContexts[$context->id()]) short-circuits before calling evaluateContextConditions() if the context is already in the active set.
3. Reorders checks — !$context->disabled() is checked first (cheap), then the duplicate check (cheap), then evaluateContextConditions() (expensive) last. The original checked evaluateContextConditions() before disabled().
Assessment
The changes are sensible. A couple of observations:
Minor: conditionsHasBeenEvaluated() already guards against re-evaluation
getActiveContexts() at line 237 checks conditionsHasBeenEvaluated() and returns early if already evaluated, so the duplicate-entry guard in evaluateContexts() should only matter if evaluateContexts() is called directly more than once, or if there are somehow duplicate context entities returned by getContexts(). It's defensive but reasonable.
Minor: callers may depend on numeric array keys
The original $this->activeContexts[] produced a numerically-indexed array. The new code produces an associative array keyed by context ID. Any caller doing something like $activeContexts[0] would break — though this is unlikely since the typical usage is foreach. Worth verifying no callers index numerically.
The reorder of disabled() before evaluateContextConditions() is a good optimization
In the original, disabled contexts still had their conditions evaluated (wastefully) before being filtered out. Moving !$context->disabled() first avoids unnecessary evaluation work.
Overall: clean, small, and beneficial. Good to merge assuming no callers rely on numeric array indexing.
Comment #6
loze commentedFor the record, I have been using this in production on 3 separate sites for the past year w/o any issues.