[PR #5842] [MERGED] fix(common): resolve TypeError when opening request from search results #5377

Closed
opened 2026-03-17 02:49:52 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5842
Author: @Leon-Luu
Created: 2/5/2026
Status: Merged
Merged: 2/24/2026
Merged by: @jamesgeorge007

Base: nextHead: fix_search_auth_issue


📝 Commits (2)

  • b6ed8ce fix: typeerror when open request from search results
  • ed48261 fix(common): mark team collection data fields as optional in type casts

📊 Changes

2 files changed (+13 additions, -13 deletions)

View changed files

📝 packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts (+10 -10)
📝 packages/hoppscotch-common/src/services/team-collection.service.ts (+3 -3)

📄 Description

In packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts, the findInheritableParentAuth method attempts to access the authType property on inheritedAuth without first verifying that inheritedAuth is defined.

Problematic code:

const inheritedAuth = parentInheritedData.auth

if (inheritedAuth.authType !== "inherit") {
  // ...
}

When a parent collection has null or undefined auth data in its parsed JSON, parentInheritedData.auth will be undefined, causing the error when trying to access .authType.

Solution

Add a null/undefined check before accessing the authType property:

const inheritedAuth = parentInheritedData.auth

if (inheritedAuth && inheritedAuth.authType !== "inherit") {
  // ...
}

Impact

  • Severity: High - Users cannot open requests from search results
  • Affected Component: Team Collections Search
  • User Impact: Blocks workflow when using search functionality

Closes https://github.com/hoppscotch/hoppscotch/issues/5841

Whats changed

  • Modified packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts line 414 to include a null check before accessing the authType property.

  • Extended the fix to mark auth, headers, and variables as optional in all three JSON.parse type casts across findInheritableParentAuth, findInheritableParentHeaders, and findInheritableParentVariables. TeamCollection.data is a nullable JSON with no enforced shape on the backend, and older collections may be missing any of these fields. The existing truthy guards already handled this defensively — the casts now accurately reflect the actual runtime contract—same fix applied to cascadeParentCollectionForProperties in team-collection.service.ts.

Notes to reviewers

Tested OK


Summary by cubic

Fixed a crash when opening requests from search results by safely handling missing auth in team collection search. Updated TeamCollection.data type casts to mark auth/headers/variables as optional and added null checks before reading authType, preventing TypeErrors when parent collections lack these fields.

Written for commit ed4826181e. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5842 **Author:** [@Leon-Luu](https://github.com/Leon-Luu) **Created:** 2/5/2026 **Status:** ✅ Merged **Merged:** 2/24/2026 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `fix_search_auth_issue` --- ### 📝 Commits (2) - [`b6ed8ce`](https://github.com/hoppscotch/hoppscotch/commit/b6ed8ce32675b5b74d602f60aa47747f410574da) fix: typeerror when open request from search results - [`ed48261`](https://github.com/hoppscotch/hoppscotch/commit/ed4826181e69d77d772851b6299d28a48833e5e8) fix(common): mark team collection data fields as optional in type casts ### 📊 Changes **2 files changed** (+13 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts` (+10 -10) 📝 `packages/hoppscotch-common/src/services/team-collection.service.ts` (+3 -3) </details> ### 📄 Description In `packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts`, the `findInheritableParentAuth` method attempts to access the `authType` property on `inheritedAuth` without first verifying that `inheritedAuth` is defined. **Problematic code:** ```typescript const inheritedAuth = parentInheritedData.auth if (inheritedAuth.authType !== "inherit") { // ... } ``` When a parent collection has `null` or `undefined` auth data in its parsed JSON, `parentInheritedData.auth` will be `undefined`, causing the error when trying to access `.authType`. ## Solution Add a null/undefined check before accessing the `authType` property: ```typescript const inheritedAuth = parentInheritedData.auth if (inheritedAuth && inheritedAuth.authType !== "inherit") { // ... } ``` ## Impact - **Severity**: High - Users cannot open requests from search results - **Affected Component**: Team Collections Search - **User Impact**: Blocks workflow when using search functionality Closes https://github.com/hoppscotch/hoppscotch/issues/5841 ### Whats changed - Modified `packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts` line 414 to include a null check before accessing the `authType` property. - Extended the fix to mark auth, headers, and variables as optional in all three JSON.parse type casts across `findInheritableParentAuth`, `findInheritableParentHeaders`, and `findInheritableParentVariables`. `TeamCollection.data` is a nullable JSON with no enforced shape on the backend, and older collections may be missing any of these fields. The existing truthy guards already handled this defensively — the casts now accurately reflect the actual runtime contract—same fix applied to `cascadeParentCollectionForProperties` in `team-collection.service.ts`. ### Notes to reviewers <!-- Any information you feel the reviewer should know about when reviewing your PR --> Tested OK <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed a crash when opening requests from search results by safely handling missing auth in team collection search. Updated TeamCollection.data type casts to mark auth/headers/variables as optional and added null checks before reading authType, preventing TypeErrors when parent collections lack these fields. <sup>Written for commit ed4826181e69d77d772851b6299d28a48833e5e8. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:49:52 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5377
No description provided.