Skip to content

fix: improve environment variable comparison by stripping UIDs - #7100

Merged
sid-bruno merged 3 commits into
usebruno:mainfrom
sid-bruno:fix/BRU-2647
Feb 11, 2026
Merged

sid-bruno merged 3 commits into
usebruno:mainfrom
sid-bruno:fix/BRU-2647

Conversation

@sid-bruno

@sid-bruno sid-bruno commented Feb 10, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

  • Uses index as it's a more stable id compared to the uid since it changes on each save
  • For the comparison we strip the UID since it might change and only use the value set instead
  • Increase the auto save minimum since anything below 500 is too less for users to react to changes.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed focus being lost in environment variables table when saving.
  • Chores

    • Increased minimum Auto Save interval to 500ms.
    • Enhanced environment variable comparison logic.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 targets BRU-2647 by improving how the Environment Variables editor detects changes and maintains UI focus, specifically by avoiding UID-driven false diffs and adding an end-to-end regression test around focus retention during save.

Changes:

  • Added a Playwright regression test to ensure the environment variable name input keeps focus after the save hotkey.
  • Introduced stripEnvVarUid and updated EnvironmentVariablesTable’s “modified/has changes” comparisons to ignore UIDs.
  • Changed the virtualized table row keying strategy (computeItemKey) to avoid UID-based remounts.

Reviewed changes

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

File Description
tests/environments/focus-retention/environment-focus.spec.ts Adds an E2E test verifying focus retention after Ctrl+S save.
packages/bruno-app/src/utils/environments.js Adds a helper to remove UID (and currently other fields) for comparisons.
packages/bruno-app/src/components/EnvironmentVariablesTable/index.js Uses UID-stripped comparisons for modified/draft/save detection and changes row key computation.

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

@sid-bruno

Copy link
Copy Markdown
Collaborator Author

Found another issue with search that is not tied for v3.1.0 so moving the fix to another PR

@coderabbitai

coderabbitai Bot commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR refactors environment variable comparison logic by introducing UID stripping to prevent false change detection, updates auto-save validation thresholds from 100ms to 500ms, and adds a test for environment variable focus retention during saves.

Changes

Cohort / File(s) Summary
Environment Variables Table
packages/bruno-app/src/components/EnvironmentVariablesTable/index.js
Refactors row key generation from item.variable.uid to ${environment.uid}-${item.index} and applies stripEnvVarUid utility across state derivations for change detection to exclude UID differences.
Utilities
packages/bruno-app/src/utils/environments.js
Adds new stripEnvVarUid function that extracts name, value, type, enabled, and secret fields from environment variables, enabling UID-agnostic comparisons.
Preferences Validation
packages/bruno-app/src/components/Preferences/General/index.js
Increases auto-save interval minimum validation threshold from 100ms to 500ms.
Focus Retention Tests
tests/environments/focus-retention/environment-focus.spec.ts
Adds Playwright test suite verifying environment variable input focus is retained after Ctrl+S save action.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

🔧 UIDs stripped away, comparisons ring clear,
Focus stays put when the saves appear,
Delays tuned tighter to 500ms strong,
Variables dance where they all belong! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a stripEnvVarUid function and applying it throughout the codebase to improve environment variable comparison logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
packages/bruno-app/src/utils/environments.js (1)

58-61: Consider a defensive guard for null/undefined input.

Other helpers in this file (e.g., toPersistedEnvVarForSave at line 16) guard with v || {}. stripEnvVarUid will throw a TypeError if it receives null or undefined. Given it's used in .map() chains on arrays that flow from Redux/draft state, it's low-risk but inconsistent.

🛡️ Optional defensive tweak
 export const stripEnvVarUid = (variable) => {
-  const { name, value, type, enabled, secret } = variable;
+  const { name, value, type, enabled, secret } = variable || {};
   return { name, value, type, enabled, secret };
 };
packages/bruno-app/src/components/EnvironmentVariablesTable/index.js (2)

206-210: Line 210: long line — consider breaking for readability.

This single line is ~105 characters. Not a blocker, but it could benefit from a line break.

✨ Optional formatting
-      const existingDraftJson = existingDraftVariables ? JSON.stringify(existingDraftVariables.map(stripEnvVarUid)) : null;
+      const existingDraftJson = existingDraftVariables
+        ? JSON.stringify(existingDraftVariables.map(stripEnvVarUid))
+        : null;

322-323: Same long-line note here.

Line 323 is ~100+ characters with two JSON.stringify + map calls. Consider splitting for readability.

✨ Optional formatting
-    const hasChanges = JSON.stringify(variablesToSave.map(stripEnvVarUid)) !== JSON.stringify(savedValues.map(stripEnvVarUid));
+    const strippedCurrent = JSON.stringify(variablesToSave.map(stripEnvVarUid));
+    const strippedSaved = JSON.stringify(savedValues.map(stripEnvVarUid));
+    const hasChanges = strippedCurrent !== strippedSaved;
tests/environments/focus-retention/environment-focus.spec.ts (1)

11-27: Wrap test phases in test.step for better report readability.

Per the coding guidelines, test.step usage is encouraged. This test has clear phases that would benefit from it.

♻️ Suggested refactor with test.step
   test('should keep focus on name input after save hotkey', async ({ page, createTmpDir }) => {
-    await createCollection(page, 'env-focus', await createTmpDir('env-focus'));
-    await createEnvironment(page, 'Focus Env', 'collection');
-
-    const nameInput = page.locator('input[name="0.name"]');
-    await nameInput.waitFor({ state: 'visible' });
-    await nameInput.click();
-    await page.keyboard.type('apiKey');
-    await expect(nameInput).toBeFocused();
-
-    await page.keyboard.press('Control+s');
-    await expect(page.getByText('Changes saved successfully').last()).toBeVisible({ timeout: 5000 });
-
-    // intentionally wait a few seconds because the focus is lost after a while
-    await page.waitForTimeout(1000);
-    await expect(nameInput).toBeFocused();
+    await test.step('Setup collection and environment', async () => {
+      await createCollection(page, 'env-focus', await createTmpDir('env-focus'));
+      await createEnvironment(page, 'Focus Env', 'collection');
+    });
+
+    const nameInput = page.locator('input[name="0.name"]');
+
+    await test.step('Type variable name and verify focus', async () => {
+      await nameInput.waitFor({ state: 'visible' });
+      await nameInput.click();
+      await page.keyboard.type('apiKey');
+      await expect(nameInput).toBeFocused();
+    });
+
+    await test.step('Save and verify focus is retained', async () => {
+      await page.keyboard.press('Control+s');
+      await expect(page.getByText('Changes saved successfully').last()).toBeVisible({ timeout: 5000 });
+
+      // intentionally wait a few seconds because the focus is lost after a while
+      await page.waitForTimeout(1000);
+      await expect(nameInput).toBeFocused();
+    });
   });

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sid-bruno
sid-bruno merged commit 828cb19 into usebruno:main Feb 11, 2026
6 of 7 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 18, 2026
3 of 5 tasks
@coderabbitai coderabbitai Bot mentioned this pull request May 29, 2026
6 tasks
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants