fix(AddIgniteUIBlazor): clone modulesToLoad array to prevent aliasing - #313
Conversation
|
@copilot update PR description with the issue explanation and resolution and title with the fix (preferably as semantic commit) |
I don't have the permissions to update the PR title/description directly, but here's the proposed update: Title: Description: |
AddIgniteUIBlazor PR…event aliasing Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com>
9f73339 to
3310548
Compare
|
@copilot There should be now unit tests for |
There was a problem hiding this comment.
Pull request overview
This PR targets the AddIgniteUIBlazor(params Type[] modulesToLoad) service-registration overload to make module preloading deterministic by preventing caller-side mutation of the modulesToLoad array from affecting what gets loaded later (due to deferred execution of the scoped factory).
Changes:
- Introduces a clone of the
modulesToLoadarray via a collection expression ([.. modulesToLoad]) before wrapping it inReadOnlyCollection<Type>.
| Type[] modules = modulesToLoad != null && modulesToLoad.Length > 0 ? [.. modulesToLoad] : []; | ||
| bs = bs.WithModulesToLoad(modules.Length > 0 ? new ReadOnlyCollection<Type>(modules) : null); |
…aliasing test Co-authored-by: damyanpetev <3198469+damyanpetev@users.noreply.github.com>
Added |
Problem
In the params-only overload of
AddIgniteUIBlazor, themodulesToLoadarray passed by the caller was wrapped directly in aReadOnlyCollection<Type>without cloning it first. Because the service factory lambda is deferred (executed when the scoped service is first resolved), a caller who mutates the original array between registration and resolution would inadvertently change the set of modules that get loaded — making registration non-deterministic.Resolution
Clone the array via a spread expression (
[.. modulesToLoad]) before wrapping it inReadOnlyCollection<Type>, capturing an independent snapshot of the caller's input at registration time.Original PR: #312
Triggering review: #312 (comment)