Skip to content

fix: prevent crash and handle missing organizationInformation#22

Closed
swathi2006 wants to merge 2 commits intoAOSSIE-Org:mainfrom
swathi2006:org-info-bug
Closed

fix: prevent crash and handle missing organizationInformation#22
swathi2006 wants to merge 2 commits intoAOSSIE-Org:mainfrom
swathi2006:org-info-bug

Conversation

@swathi2006
Copy link

@swathi2006 swathi2006 commented Mar 20, 2026

Addressed Issues:

Fixes #20

Screenshots/Recordings:

image

Additional Notes:

Summary

Fixed runtime crash when organizationInformation is not provided and improved UI handling.

Changes

  • Added conditional rendering to prevent accessing undefined props
  • Avoided rendering empty organization section
  • Added fallback message when organization data is missing
  • Added inline comments for clarity

Result

Component no longer crashes and provides a clean fallback UI when organization information is not available.

Checklist

  • My code follows the project's code style and conventions
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contributing Guidelines

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • Bug Fixes
    • Support Us section now gracefully handles missing organization or call-to-action data: empty sections are hidden and a helpful message is shown instead of an empty or broken area, preventing render issues.

@github-actions github-actions bot added bug Something isn't working frontend Changes to frontend code javascript JavaScript/TypeScript code changes size/S Small PR (11-50 lines changed) first-time-contributor First PR of an external contributor pending-coderabbit-review labels Mar 20, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Walkthrough

SupportUsButton now defensively handles missing organizationInformation and ctaSection props: it logs console.warn when either is absent, assigns local nullable refs (org, cta), and conditionally renders each section only when the corresponding data is present; rendering structure is unchanged when props exist.

Changes

Cohort / File(s) Summary
Conditional rendering and runtime guards
src/components/SupportUsButton.tsx
Adds runtime null-coalescing to organizationInformation and ctaSection, emits console.warn when missing, and changes both sections to conditional render ({org && (...)}, {cta && (...)}); internal references switched to org.* / cta.*.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

Typescript Lang

Poem

🐰 I nibble at props with careful delight,
If org or cta hide, I warn in the night.
No crashes, just hops through conditional gates,
A tidy button that gently patiently waits. 🥕

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: handling missing organizationInformation to prevent crashes, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR fully addresses all coding requirements from issue #20: adds defensive null checks with console.warn logging, implements conditional rendering for missing data, and gracefully handles undefined organizationInformation and ctaSection props.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of preventing crashes when organizationInformation is undefined; no unrelated modifications were introduced.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can generate a title for your PR based on the changes with custom instructions.

Set the reviews.auto_title_instructions setting to generate a title for your PR based on the changes in the PR with custom instructions.

Copy link

@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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/SupportUsButton.tsx`:
- Around line 243-247: The hardcoded fallback string "Organization details are
not available." inside the SupportUsButton component should be externalized for
i18n: replace the literal in the <p className="text-center text-gray-500 mt-10">
element with a translation lookup (e.g., use the project's translation helper
such as t('support.organizationDetailsUnavailable') or useTranslation().t) and
add a corresponding key ("support.organizationDetailsUnavailable") with
translations to the project's resource files; also add the necessary
import/usage of the app's i18n hook/helper at the top of SupportUsButton.tsx
(e.g., import { useTranslation } from '...') if not already present.
- Around line 243-247: The component accesses the optional prop ctaSection
without null checks, which can crash when it's undefined; update SupportUsButton
to guard all uses of ctaSection (references around where you currently read
ctaSection, and in the render block that shows CTA content) by adding a
conditional render (e.g., only render the CTA block when ctaSection is truthy)
or use safe access (optional chaining) for properties on ctaSection, ensuring
the same checks are applied to every place ctaSection is used (the three current
access sites) so no property is dereferenced when it's undefined.
- Around line 134-136: The prop organizationInformation is treated as optional
in the SupportUsButton component (conditional render at organizationInformation
? ...), so update its type to be optional in the type declarations: change the
required property declaration for organizationInformation to an optional one
(e.g., organizationInformation?: OrganizationInformation) in the types file and
ensure any imports/uses of that prop (SupportUsButton props/interface) reflect
the optional type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3dcbdd26-4f0b-4cd2-8220-f6ed712067da

📥 Commits

Reviewing files that changed from the base of the PR and between 62828cd and 8ad2874.

📒 Files selected for processing (1)
  • src/components/SupportUsButton.tsx

@github-actions github-actions bot added size/M Medium PR (51-200 lines changed) and removed size/S Small PR (11-50 lines changed) labels Mar 20, 2026
Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/SupportUsButton.tsx (1)

460-466: ⚠️ Potential issue | 🔴 Critical

Validate CTA URLs to prevent XSS vulnerabilities before rendering.

Line 462 passes link.url directly to the href attribute without scheme validation. If sponsorLink[].url contains arbitrary strings (including javascript: URLs), clicking the link will execute them as JavaScript, creating an XSS vulnerability. The rel="noopener noreferrer" attribute only affects window opening behavior and does not mitigate this risk. Implement URL validation to whitelist safe schemes (e.g., http://, https://, or relative URLs) before rendering the anchor element.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SupportUsButton.tsx` around lines 460 - 466, The mapping
inside SupportUsButton.tsx that renders sponsorLink (the JSX block iterating
over cta.sponsorLink) currently passes link.url directly into the anchor href;
add a URL-safety check (e.g., implement an isSafeUrl helper) to only allow
http:, https:, or safe relative paths (starting with "/") and treat anything
else as unsafe—if unsafe, render a non-navigable fallback (href="#" or omit href
and/or add aria-disabled) and avoid target="_blank" for unsafe URLs; update the
JSX that uses link.url and link.newTab to first validate via isSafeUrl(link.url)
and only inject href/target when valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/SupportUsButton.tsx`:
- Around line 75-87: The console.warn calls in the SupportUsButton component
body cause repeated warnings on every render; remove those warnings from the
render path and instead add a dev-only one-time validator using a useEffect
inside SupportUsButton (or a small validateDevProps helper called from that
effect) that checks organizationInformation and ctaSection once (empty
dependency array) and logs warnings only when process.env.NODE_ENV !==
'production'; ensure you delete the inline console.warn lines and reference the
same prop names (organizationInformation, ctaSection) in the validator so the
behavior and messages remain identical but only emit once during development.
- Around line 187-201: The rendering currently falls through to the <img> when
org.logo is undefined; update the SupportUsButton render logic to explicitly
guard the optional logo: keep the string branch for typeof org.logo ===
"string", render the <img> only when org.logo is an object (e.g., check org.logo
&& typeof org.logo !== "string"), and return null (or nothing) when org.logo is
undefined; modify the JSX around org.logo (the ternary that produces the <span>
or <img>) to use this three-way guard so src and alt are only accessed when
org.logo is a defined object.

---

Outside diff comments:
In `@src/components/SupportUsButton.tsx`:
- Around line 460-466: The mapping inside SupportUsButton.tsx that renders
sponsorLink (the JSX block iterating over cta.sponsorLink) currently passes
link.url directly into the anchor href; add a URL-safety check (e.g., implement
an isSafeUrl helper) to only allow http:, https:, or safe relative paths
(starting with "/") and treat anything else as unsafe—if unsafe, render a
non-navigable fallback (href="#" or omit href and/or add aria-disabled) and
avoid target="_blank" for unsafe URLs; update the JSX that uses link.url and
link.newTab to first validate via isSafeUrl(link.url) and only inject
href/target when valid.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3d103c05-ea7a-4e29-8535-0d66cc64c33f

📥 Commits

Reviewing files that changed from the base of the PR and between 8ad2874 and 8ed381d.

📒 Files selected for processing (1)
  • src/components/SupportUsButton.tsx

Comment on lines +75 to +87
// Ensure required props are provided to prevent runtime crashes

if (!organizationInformation) {
console.warn(
"SupportUsButton: 'organizationInformation' is required."
);
}

if (!ctaSection) {
console.warn(
"SupportUsButton: 'ctaSection' is required."
);
}
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Keep the missing-prop warnings out of the render path.

These console.warn calls fire on every re-render while the prop is absent, so parent updates and React StrictMode will spam consumer consoles. Emit them once from a dev-only validator/effect instead of the component body. As per coding guidelines, "The code adheres to best practices associated with React".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SupportUsButton.tsx` around lines 75 - 87, The console.warn
calls in the SupportUsButton component body cause repeated warnings on every
render; remove those warnings from the render path and instead add a dev-only
one-time validator using a useEffect inside SupportUsButton (or a small
validateDevProps helper called from that effect) that checks
organizationInformation and ctaSection once (empty dependency array) and logs
warnings only when process.env.NODE_ENV !== 'production'; ensure you delete the
inline console.warn lines and reference the same prop names
(organizationInformation, ctaSection) in the validator so the behavior and
messages remain identical but only emit once during development.

Comment on lines +187 to +201
{typeof org.logo === "string" ? (
<span
className="block h-fit w-fit p-4 bg-black text-white rounded-2xl"
title={organizationInformation.logo}
title={org.logo}
>
<b className="text-2xl italic">
{organizationInformation.logo}
{org.logo}
</b>
</span>
) : (
<img
className="w-24 h-24 bg-white/80 pointer-none:cursor-none select-none rounded-2xl object-cover object-center"
src={organizationInformation.logo?.src}
alt={organizationInformation.logo?.alt}
title={organizationInformation.logo?.alt}
src={org.logo?.src}
alt={org.logo?.alt}
title={org.logo?.alt}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -name "index.ts" -path "*/types/*" | head -5

Repository: AOSSIE-Org/SupportUsButton

Length of output: 90


🏁 Script executed:

find . -name "SupportUsButton.tsx" | head -5

Repository: AOSSIE-Org/SupportUsButton

Length of output: 106


🏁 Script executed:

cat -n src/types/index.ts

Repository: AOSSIE-Org/SupportUsButton

Length of output: 4642


🏁 Script executed:

cat -n src/components/SupportUsButton.tsx | head -220 | tail -80

Repository: AOSSIE-Org/SupportUsButton

Length of output: 3781


Handle the optional logo prop before rendering <img>.

organizationInformation.logo is optional (type: Image | string | undefined), but the ternary at lines 187-204 falls through to <img> when org.logo is undefined. This renders a broken image with src={undefined}. Add an explicit guard: render the span for strings, the image only when org.logo is an object, and null when undefined.

Suggested fix
-              {typeof org.logo === "string" ? (
+              {typeof org.logo === "string" ? (
                 <span
                   className="block h-fit w-fit p-4 bg-black text-white rounded-2xl"
                   title={org.logo}
                 >
                   <b className="text-2xl italic">
                     {org.logo}
                   </b>
                 </span>
-              ) : (
+              ) : org.logo ? (
                 <img
                   className="w-24 h-24 bg-white/80 pointer-none:cursor-none select-none rounded-2xl object-cover object-center"
-                  src={org.logo?.src}
-                  alt={org.logo?.alt}
-                  title={org.logo?.alt}
+                  src={org.logo.src}
+                  alt={org.logo.alt}
+                  title={org.logo.alt}
                   draggable={false}
                 />
-              )}
+              ) : null}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{typeof org.logo === "string" ? (
<span
className="block h-fit w-fit p-4 bg-black text-white rounded-2xl"
title={organizationInformation.logo}
title={org.logo}
>
<b className="text-2xl italic">
{organizationInformation.logo}
{org.logo}
</b>
</span>
) : (
<img
className="w-24 h-24 bg-white/80 pointer-none:cursor-none select-none rounded-2xl object-cover object-center"
src={organizationInformation.logo?.src}
alt={organizationInformation.logo?.alt}
title={organizationInformation.logo?.alt}
src={org.logo?.src}
alt={org.logo?.alt}
title={org.logo?.alt}
{typeof org.logo === "string" ? (
<span
className="block h-fit w-fit p-4 bg-black text-white rounded-2xl"
title={org.logo}
>
<b className="text-2xl italic">
{org.logo}
</b>
</span>
) : org.logo ? (
<img
className="w-24 h-24 bg-white/80 pointer-none:cursor-none select-none rounded-2xl object-cover object-center"
src={org.logo.src}
alt={org.logo.alt}
title={org.logo.alt}
draggable={false}
/>
) : null}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SupportUsButton.tsx` around lines 187 - 201, The rendering
currently falls through to the <img> when org.logo is undefined; update the
SupportUsButton render logic to explicitly guard the optional logo: keep the
string branch for typeof org.logo === "string", render the <img> only when
org.logo is an object (e.g., check org.logo && typeof org.logo !== "string"),
and return null (or nothing) when org.logo is undefined; modify the JSX around
org.logo (the ternary that produces the <span> or <img>) to use this three-way
guard so src and alt are only accessed when org.logo is a defined object.

@swathi2006 swathi2006 closed this Mar 21, 2026
@swathi2006 swathi2006 deleted the org-info-bug branch March 21, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working first-time-contributor First PR of an external contributor frontend Changes to frontend code javascript JavaScript/TypeScript code changes pending-coderabbit-review size/M Medium PR (51-200 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Runtime crash when organizationInformation is undefined

1 participant