Skip to content

fix: Maintainability issues#27

Merged
Dhruwang merged 4 commits intomainfrom
fix-sonar-issues
Sep 24, 2025
Merged

fix: Maintainability issues#27
Dhruwang merged 4 commits intomainfrom
fix-sonar-issues

Conversation

@Dhruwang
Copy link
Copy Markdown
Member

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 24, 2025

Walkthrough

This PR removes the StorageAPI file-upload implementation and its tests, and changes the React Native package index to re-export Formbricks as the default. Several timestamp calculations are simplified to use Date.now(). The setup sync check (shouldSyncConfig) now compares only environmentId and appUrl; handleErrorOnFirstSetup uses Date.now(). Survey listener notification switches to for-of iteration over the Set. shouldDisplayBasedOnPercentage now uses a direct Math.random() probability check. Other edits are formatting and comment cleanups.

Pre-merge checks

❌ Failed checks (2 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title "fix: Maintainability issues" is broadly related to this changeset because the PR contains multiple maintainability-focused edits (re-exporting Formbricks, Date.now simplifications, loop refactors, utility tweaks), but it is generic and does not call out the most significant change (the removal of the StorageAPI class and its tests), so it lacks specificity for reviewers. Please provide a more specific title that highlights the primary change, for example: "refactor(react-native): remove StorageAPI and tests; misc maintainability fixes (re-export Formbricks, Date.now adjustments)"; a concise, explicit title helps reviewers quickly identify the PR's main impact.
Description Check ❓ Inconclusive No pull request description was provided; the check is lenient but the absence of any description leaves the PR intent, rationale, and key details unclear, so the result is inconclusive. Add a brief description summarizing the main changes (for example: removal of StorageAPI and its tests, re-export of Formbricks, Date.now and loop/utility cleanups) and any rationale or migration notes so reviewers understand the intent and scope.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a8cab6 and 8366d9c.

📒 Files selected for processing (1)
  • packages/react-native/src/lib/survey/store.ts (1 hunks)
🔇 Additional comments (3)
packages/react-native/src/lib/survey/store.ts (3)

21-22: Verify id-only change detection is sufficient.

If a survey with the same id is updated (e.g., content or settings changed), this guard suppresses updates/notifications. Confirm the invariant that id changes whenever meaningful fields change; otherwise consider deep/structural comparison or always notifying on object identity change.


23-25: Iterate a snapshot of listeners to avoid mid-iteration mutation (skip/double notifications).

Mutating the Set during notification can change the iteration. Use a shallow copy.

-      for (const listener of this.listeners) {
+      for (const listener of [...this.listeners]) {
         listener(this.survey, prevSurvey);
-      }
+      }

33-35: Apply the same snapshot iteration on reset.

Mirror the fix here to keep behavior consistent.

-      for (const listener of this.listeners) {
+      for (const listener of [...this.listeners]) {
         listener(this.survey, prevSurvey);
-      }
+      }

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56fc1b6 and 7f96386.

📒 Files selected for processing (8)
  • packages/react-native/src/index.ts (1 hunks)
  • packages/react-native/src/lib/common/file-upload.ts (0 hunks)
  • packages/react-native/src/lib/common/setup.ts (2 hunks)
  • packages/react-native/src/lib/common/tests/file-upload.test.ts (0 hunks)
  • packages/react-native/src/lib/common/utils.ts (2 hunks)
  • packages/react-native/src/lib/environment/state.ts (1 hunks)
  • packages/react-native/src/lib/survey/store.ts (1 hunks)
  • packages/react-native/src/lib/user/state.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/react-native/src/lib/common/file-upload.ts
  • packages/react-native/src/lib/common/tests/file-upload.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/react-native/src/lib/common/utils.ts (1)
packages/react-native/src/types/error.ts (1)
  • Result (11-11)
🔇 Additional comments (6)
packages/react-native/src/lib/environment/state.ts (1)

101-101: LGTM: Consistent Date.now()-based expiry calculation

Clearer and consistent with other modules.

packages/react-native/src/lib/user/state.ts (1)

38-38: LGTM: Expiry calculation aligned to Date.now()

Matches environment state handling.

packages/react-native/src/lib/common/utils.ts (1)

18-30: LGTM: wrapThrowsAsync formatting only

No behavior change; reads cleaner.

packages/react-native/src/lib/common/setup.ts (2)

415-415: LGTM: Date.now() for error expiry

Consistent and clear 10‑minute window computation.


229-231: Remove unnecessary environment presence check in shouldSyncConfig

Condition still requires existingConfig.environment, which contradicts the PR goal and can skip valid syncs when env is absent but ids match.

-  return Boolean(
-    existingConfig?.environment &&
-    existingConfig.environmentId === configInput.environmentId &&
-    existingConfig.appUrl === configInput.appUrl
-  );
+  return Boolean(
+    existingConfig?.environmentId === configInput.environmentId &&
+    existingConfig?.appUrl === configInput.appUrl
+  );

Likely an incorrect or invalid review comment.

packages/react-native/src/index.ts (1)

41-41: Potential export mismatch: re‑export assumes named Formbricks

File: packages/react-native/src/index.ts (line 41) — the current re‑export expects a named export Formbricks; if the target module exports a default, replace with the default re‑export:

-export { Formbricks as default } from "@/components/formbricks";
+export { default } from "@/components/formbricks";

Comment thread packages/react-native/src/lib/common/utils.ts Outdated
Comment thread packages/react-native/src/lib/survey/store.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f96386 and 0e71a2a.

📒 Files selected for processing (2)
  • packages/react-native/src/lib/common/utils.ts (2 hunks)
  • packages/react-native/src/lib/survey/store.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/react-native/src/lib/common/utils.ts (1)
packages/react-native/src/types/error.ts (1)
  • Result (11-11)
🔇 Additional comments (2)
packages/react-native/src/lib/survey/store.ts (2)

23-25: Good fix: iterate a snapshot of listeners

Using a spread copy avoids mid-iteration mutation issues. LGTM.


33-35: Consistent snapshot iteration in reset

Mirrors the set path and prevents skipped/double notifications. LGTM.

Comment thread packages/react-native/src/lib/common/utils.ts
Comment thread packages/react-native/src/lib/common/utils.ts Outdated
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e71a2a and 5a8cab6.

📒 Files selected for processing (1)
  • packages/react-native/src/lib/common/utils.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-24T10:29:57.939Z
Learnt from: Dhruwang
PR: formbricks/react-native#27
File: packages/react-native/src/lib/common/utils.ts:186-187
Timestamp: 2025-09-24T10:29:57.939Z
Learning: User claims there are checks to ensure displayPercentage is not zero in the Formbricks React Native codebase, but no such validation logic was found in the code search results.

Applied to files:

  • packages/react-native/src/lib/common/utils.ts
🧬 Code graph analysis (1)
packages/react-native/src/lib/common/utils.ts (1)
packages/react-native/src/types/error.ts (1)
  • Result (11-11)
🔇 Additional comments (1)
packages/react-native/src/lib/common/utils.ts (1)

18-30: Normalize non-Error throws; avoid unsafe cast

Ensure Result.error is always an Error and preserve a useful message.

-    async (...args: A): Promise<Result<T>> => {
-      try {
-        return {
-          ok: true,
-          data: await fn(...args),
-        };
-      } catch (error) {
-        return {
-          ok: false,
-          error: error as Error,
-        };
-      }
-    };
+    async (...args: A): Promise<Result<T>> => {
+      try {
+        return {
+          ok: true,
+          data: await fn(...args),
+        };
+      } catch (error: unknown) {
+        const err =
+          error instanceof Error
+            ? error
+            : new Error(
+                typeof error === "string"
+                  ? error
+                  : `Non-Error thrown: ${JSON.stringify(error)}`
+              );
+        return { ok: false, error: err };
+      }
+    };

Comment thread packages/react-native/src/lib/common/utils.ts
Copy link
Copy Markdown
Contributor

@pandeymangg pandeymangg left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@Dhruwang Dhruwang added this pull request to the merge queue Sep 24, 2025
Merged via the queue into main with commit faf460e Sep 24, 2025
9 checks passed
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.

2 participants