Skip to content

chore: Remove unsafe use of _get()#3606

Open
IstvanCsVarga wants to merge 1 commit intojaegertracing:mainfrom
IstvanCsVarga:remove-lodash-get
Open

chore: Remove unsafe use of _get()#3606
IstvanCsVarga wants to merge 1 commit intojaegertracing:mainfrom
IstvanCsVarga:remove-lodash-get

Conversation

@IstvanCsVarga
Copy link
Copy Markdown

@IstvanCsVarga IstvanCsVarga commented Mar 13, 2026

Which problem is this PR solving?

Resolves #3604

Replaces most lodash/get (_get()) calls with native JavaScript optional chaining (?.) and nullish coalescing (??) operators for type-safe, compiler-checked property access.

Description of the changes

  • Simple property access (17 calls): Replaced with optional chaining, e.g. _get(state, 'config.search.maxLookback') -> state.config?.search?.maxLookback
  • With default values (4 calls): Added nullish coalescing, e.g. _get(zoomTransform, 'k', 1) -> zoomTransform?.k ?? 1
  • Computed keys (1 call): Used bracket notation with optional chaining, e.g. state.ddg?.[getStateEntryKey(...)]
  • Dynamic dot-notation paths (7 calls): Kept _get in the 3 files where paths are genuinely runtime-dependent (DetailsPanel.tsx, path-agnostic-decorations.ts, process-deprecation.ts)

Type improvements

Adding type-safe access exposed two missing type definitions that _get() had been silently bypassing:

  • Added pathAgnosticDecorations to ReduxState type
  • Added cookiesToDimensions to the tracking config type

How was this change tested?

  • npm run prettier - pass
  • npm run lint (eslint + tsc-lint + prettier-lint + license checks) - pass
  • npm test - all 2565 tests pass
  • npm run build - production build succeeds

Checklist

AI Usage in this PR (choose one)

See AI Usage Policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@IstvanCsVarga IstvanCsVarga requested a review from a team as a code owner March 13, 2026 19:58
Copilot AI review requested due to automatic review settings March 13, 2026 19:58
let details = _get(res, getDetailPath as string);
let details: TDetails | undefined = (getDetailPath as string)
.split('.')
.reduce<unknown>((obj, key) => (obj as Record<string, unknown>)?.[key], res) as
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how is this better?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fair point, for these 3 files with dynamic paths (where the path string comes from config at runtime), the inline replacement is more verbose. I see a few options:

  1. Keep _get in just these 3 files where paths are truly dynamic
  2. Extract a small getByPath utility (though that's basically reimplementing _get)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would keep _get, but I would also question why is it that the paths are dynamic, it feels fishy. When there are truly dynamic values the data structure would be a map, not an object.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, I'll revert the dynamic-path files to keep _get. The dynamic paths do come from the user-configured decoration schemas (summaryPath, detailPath, etc.) that navigate arbitrary API response structures, so the paths are actually runtime-dependent. But restructuring that is probably a another discussion

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes remaining usages of lodash/get (_get()) across Jaeger UI and replaces them with native optional chaining / nullish coalescing (and explicit dot-path traversal where paths are dynamic), improving type-safety and making missing properties compiler-visible.

Changes:

  • Replaced _get() calls with ?. / ?? across UI, reducers, and utilities.
  • Implemented explicit runtime dot-path traversal (split('.').reduce(...)) for dynamically-computed paths.
  • Updated TypeScript types to reflect previously-implicit state/config shape (ReduxState.pathAgnosticDecorations, Config.tracking.cookiesToDimensions).

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/jaeger-ui/src/utils/tracking/ga.ts Uses optional chaining for tracking config access and window.location.search parsing.
packages/jaeger-ui/src/utils/plexus/set-on-graph.ts Replaces _get() defaulting with ?? for zoom scale access.
packages/jaeger-ui/src/utils/config/process-deprecation.ts Replaces _get() with dot-path traversal when transferring deprecated config values.
packages/jaeger-ui/src/utils/DraggableManager/DraggableManager.ts Replaces _get(document, 'body.style') with document.body?.style.
packages/jaeger-ui/src/types/index.ts Adds pathAgnosticDecorations to ReduxState type.
packages/jaeger-ui/src/types/config.ts Adds tracking.cookiesToDimensions to config typing.
packages/jaeger-ui/src/reducers/embedded.ts Replaces _get(window, 'location.search') with window.location?.search.
packages/jaeger-ui/src/model/path-agnostic-decorations/index.tsx Uses typed optional chaining for decoration state extraction.
packages/jaeger-ui/src/components/TracePage/index.tsx Replaces _get() access for vertices/spans in UI find logic.
packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanTreeOffset.tsx Replaces _get() access to relatedTarget.dataset with optional chaining.
packages/jaeger-ui/src/components/TracePage/TracePageHeader/TracePageHeader.tsx Replaces _get() defaulting for computed “depth” header value.
packages/jaeger-ui/src/components/TraceDiff/TraceDiffGraph/traceDiffGraphUtils.ts Replaces _get(...,'size') with optional chaining on size.
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.tsx Replaces _get() state reads with optional chaining on state.config.search.
packages/jaeger-ui/src/components/DeepDependencies/traces.tsx Replaces _get() for graphState.model.hash with safe discriminated access.
packages/jaeger-ui/src/components/DeepDependencies/index.tsx Replaces _get() usage for hash and DDG state entry computed key access.
packages/jaeger-ui/src/components/DeepDependencies/SidePanel/DetailsPanel.tsx Replaces _get() with dot-path traversal for decoration detail/column defs extraction.
packages/jaeger-ui/src/actions/path-agnostic-decorations.ts Replaces _get() with dot-path traversal + nullish defaulting for decoration values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IstvanCsVarga IstvanCsVarga changed the title Remove unsafe use of lodash _get() chore: Remove unsafe use of _get() Mar 13, 2026
Copilot AI review requested due to automatic review settings March 14, 2026 19:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses unsafe lodash/get (_get) usage by replacing most calls with native optional chaining (?.) and nullish coalescing (??) to make property access more type-safe and compiler-checked across Jaeger UI.

Changes:

  • Replaced many _get() usages with ?. / ?? in UI, reducers, and utilities.
  • Extended type definitions to reflect actual state/config fields used at runtime (e.g., Redux state slice and tracking config).
  • Kept dynamic runtime-dependent access patterns in the few places where paths are genuinely dynamic (per PR description).

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/jaeger-ui/src/utils/tracking/ga.ts Removes _get usage for GA config/query access; uses optional chaining on tracking config.
packages/jaeger-ui/src/utils/plexus/set-on-graph.ts Replaces _get default access for zoom scale with ?. / ??.
packages/jaeger-ui/src/utils/DraggableManager/DraggableManager.ts Replaces _get(document, 'body.style') with document.body?.style.
packages/jaeger-ui/src/types/index.ts Adds pathAgnosticDecorations to ReduxState typing.
packages/jaeger-ui/src/types/config.ts Adds tracking.cookiesToDimensions typing.
packages/jaeger-ui/src/reducers/embedded.ts Replaces _get(window, 'location.search') with window.location?.search.
packages/jaeger-ui/src/model/path-agnostic-decorations/index.tsx Replaces dynamic _get paths with structured optional chaining/bracket access.
packages/jaeger-ui/src/components/TracePage/index.tsx Replaces _get usage for vertices/spans with optional chaining/defaults.
packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanTreeOffset.tsx Replaces _get on relatedTarget dataset access with direct access + assertions.
packages/jaeger-ui/src/components/TracePage/TracePageHeader/TracePageHeader.tsx Replaces _get around _maxBy() result with ?. / ??.
packages/jaeger-ui/src/components/TraceDiff/TraceDiffGraph/traceDiffGraphUtils.ts Replaces _get(..., 'size') with ?.size.
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.tsx Replaces _get(state, 'config.search.*') with optional chaining.
packages/jaeger-ui/src/components/DeepDependencies/traces.tsx Replaces _get(graphState, 'model.hash') with guarded direct access.
packages/jaeger-ui/src/components/DeepDependencies/index.tsx Replaces _get for hash/state access and uses optional chaining for keyed lookups.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/jaeger-ui/src/components/DeepDependencies/traces.tsx
Comment thread packages/jaeger-ui/src/model/path-agnostic-decorations/index.tsx
Copilot AI review requested due to automatic review settings March 18, 2026 10:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes most uses of lodash/get in jaeger-ui in favor of optional chaining / nullish coalescing to make property access type-safe and compiler-checked (per #3604), plus updates a couple of types that _get() had been masking.

Changes:

  • Replaced _get() calls across UI/redux/utils code with ?. / ?? (keeping _get only where paths are runtime-dynamic).
  • Added missing type fields: ReduxState.pathAgnosticDecorations and Config.tracking.cookiesToDimensions.
  • Adjusted several call sites to preserve previous defaults (e.g. ?? [], ?? 1) and improve event target handling.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/jaeger-ui/src/utils/tracking/ga.ts Replaces _get(config, ...) and _get(window, ...) with optional chaining; relies on updated tracking config typing.
packages/jaeger-ui/src/utils/plexus/set-on-graph.ts Replaces _get(zoomTransform, 'k', 1) with zoomTransform?.k ?? 1 for default scaling.
packages/jaeger-ui/src/utils/DraggableManager/DraggableManager.ts Replaces _get(document, 'body.style') with document.body?.style.
packages/jaeger-ui/src/types/index.ts Adds pathAgnosticDecorations slice to ReduxState.
packages/jaeger-ui/src/types/config.ts Adds tracking.cookiesToDimensions to the Config type.
packages/jaeger-ui/src/reducers/embedded.ts Replaces _get(window, 'location.search') with window.location?.search.
packages/jaeger-ui/src/model/path-agnostic-decorations/index.tsx Replaces dynamic _get(state, \pathAgnosticDecorations...`)` with direct typed access into the decorations state.
packages/jaeger-ui/src/components/TracePage/index.tsx Replaces _get() usages for trace DAG vertices/spans with ?./?? equivalents.
packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanTreeOffset.tsx Replaces _get(event, 'relatedTarget.dataset...') with a local relatedTarget variable and direct access after type guard.
packages/jaeger-ui/src/components/TracePage/TracePageHeader/TracePageHeader.tsx Replaces _get(_maxBy(...), 'depth', 0) with ?.depth ?? 0.
packages/jaeger-ui/src/components/TraceDiff/TraceDiffGraph/traceDiffGraphUtils.ts Replaces _get(set, 'size') with set?.size.
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.tsx Replaces _get(state, 'config.search.*') with state.config?.search?.*.
packages/jaeger-ui/src/components/DeepDependencies/traces.tsx Replaces _get(graphState, 'model.hash') with a structural guard and direct access.
packages/jaeger-ui/src/components/DeepDependencies/index.tsx Replaces _get() with optional chaining / bracket access for ddg state entry + hash extraction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/jaeger-ui/src/utils/tracking/ga.ts
Comment thread packages/jaeger-ui/src/components/DeepDependencies/index.tsx Outdated
Comment thread packages/jaeger-ui/src/model/path-agnostic-decorations/index.tsx
const getUrlArg = { uiFind, ...urlState, ...newValues, ...extraUrlArgs };
const hash = _get(graphState, 'model.hash');
const hash =
graphState && graphState.state === fetchedState.DONE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
graphState && graphState.state === fetchedState.DONE
graphState?.state === fetchedState.DONE

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied in 4f5c4e4. Also applied the same simplification to the identical pattern in mapStateToProps for consistency.

Copilot AI review requested due to automatic review settings April 11, 2026 13:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes most remaining usages of lodash/get (_get) in jaeger-ui in favor of optional chaining (?.) and nullish coalescing (??), improving type safety and allowing the TypeScript compiler to catch invalid property paths (per #3604).

Changes:

  • Replaced a broad set of _get() calls with ?. / ?? across UI components and utilities.
  • Added missing type surface area exposed by the migration (Redux pathAgnosticDecorations slice and tracking cookiesToDimensions config).
  • Simplified a few call sites where _get() had been masking type issues (e.g., GA cookies-to-dimensions iteration).

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/jaeger-ui/src/utils/tracking/ga.ts Removes _get usage for GA config/query access and relies on typed config fields.
packages/jaeger-ui/src/utils/plexus/set-on-graph.ts Replaces _get(zoomTransform, 'k', 1) with zoomTransform?.k ?? 1.
packages/jaeger-ui/src/utils/DraggableManager/DraggableManager.ts Replaces _get(document, 'body.style') with document.body?.style.
packages/jaeger-ui/src/types/index.ts Adds pathAgnosticDecorations to ReduxState.
packages/jaeger-ui/src/types/config.ts Adds tracking.cookiesToDimensions typing to match runtime usage.
packages/jaeger-ui/src/reducers/embedded.ts Removes _get(window, 'location.search') in favor of window.location?.search.
packages/jaeger-ui/src/model/path-agnostic-decorations/index.tsx Replaces _get path lookups with direct indexed access into pathAgnosticDecorations.
packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanTreeOffset.tsx Removes _get and uses relatedTarget type guard + direct dataset access.
packages/jaeger-ui/src/components/TracePage/TracePageHeader/TracePageHeader.tsx Replaces _get around _maxBy(...) with optional chaining + ??.
packages/jaeger-ui/src/components/TracePage/index.tsx Replaces _get with ?./?? for trace graph vertices and spans access.
packages/jaeger-ui/src/components/TraceDiff/TraceDiffGraph/traceDiffGraphUtils.ts Replaces _get(..., 'size') with optional chaining on .size.
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.tsx Replaces _get(state, 'config.search.*') with optional chaining.
packages/jaeger-ui/src/components/DeepDependencies/traces.tsx Removes _get(graphState, 'model.hash') in favor of guarded direct access.
packages/jaeger-ui/src/components/DeepDependencies/index.tsx Removes _get usages for hash and DDG state entry access (computed keys).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Parship12
Copy link
Copy Markdown
Member

@IstvanCsVarga Can you please resolve the merge conflicts?

Replaces most lodash _get() calls with native optional chaining (?.) and
nullish coalescing (??) operators for type-safe, compiler-checked
property access.

Kept _get in 3 files where the path is genuinely runtime-dependent
(comes from user-configured schemas at runtime): DetailsPanel.tsx,
actions/path-agnostic-decorations.ts, utils/config/process-deprecation.ts.

Adds missing pathAgnosticDecorations to ReduxState type and
cookiesToDimensions to tracking config type, which were previously
bypassed by _get()'s lack of type checking.

Resolves jaegertracing#3604

Signed-off-by: Istvan Csaba Varga <istvan.csaba.varga@accenture.com>
Copilot AI review requested due to automatic review settings April 27, 2026 12:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes most unsafe lodash/get usages in jaeger-ui in favor of optional chaining / nullish coalescing, improving type-safety and letting TypeScript catch invalid property paths (per #3604).

Changes:

  • Replaced many _get() calls with ?. / ?? across UI code paths (tracking, trace pages, DDG, diff graph, search form).
  • Added missing type surface area exposed by safer property access (ReduxState.pathAgnosticDecorations, Config.tracking.cookiesToDimensions).
  • Simplified a few call sites by removing casting/overly generic access patterns once types are in place.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/jaeger-ui/src/utils/tracking/ga.ts Replaces _get() with optional chaining for GA config + query parsing; uses typed cookiesToDimensions.
packages/jaeger-ui/src/utils/plexus/set-on-graph.ts Replaces _get() defaulting with zoomTransform?.k ?? 1 for match size calculations.
packages/jaeger-ui/src/utils/DraggableManager/DraggableManager.ts Replaces _get(document, 'body.style') with document.body?.style.
packages/jaeger-ui/src/types/index.ts Adds pathAgnosticDecorations slice to ReduxState typing.
packages/jaeger-ui/src/types/config.ts Adds tracking.cookiesToDimensions to config typing.
packages/jaeger-ui/src/model/path-agnostic-decorations/index.tsx Replaces dynamic-path _get() reads with typed slice access + optional chaining.
packages/jaeger-ui/src/components/TracePage/index.tsx Replaces _get() for vertices/spans access in ui-find matching logic.
packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanTreeOffset.tsx Replaces _get(event, 'relatedTarget.dataset…') with a type-guarded local relatedTarget.
packages/jaeger-ui/src/components/TracePage/TracePageHeader/TracePageHeader.tsx Replaces _get(_maxBy(...), 'depth', 0) with optional chaining + ??.
packages/jaeger-ui/src/components/TraceDiff/TraceDiffGraph/traceDiffGraphUtils.ts Removes _get() and checks filterSpans(... )?.size directly.
packages/jaeger-ui/src/components/SearchTracePage/SearchForm.tsx Replaces config _get() reads with state.config?.search?.….
packages/jaeger-ui/src/components/DeepDependencies/traces.tsx Removes _get() for graph hash extraction when sanitizing URL state.
packages/jaeger-ui/src/components/DeepDependencies/index.tsx Removes _get() for DDG hash + state entry access using optional chaining / bracket indexing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IstvanCsVarga
Copy link
Copy Markdown
Author

@Parship12 Done — rebased onto latest main, conflicts resolved, and PR is now a single clean commit. All checks pass and the branch is mergeable.

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.

[chore]: Remove unsafe use of _get()

4 participants