Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/shade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"@tailwindcss/postcss": "catalog:",
"@testing-library/react": "catalog:",
"@types/node": "catalog:",
"@types/react-world-flags": "1.6.0",
"@typescript-eslint/eslint-plugin": "catalog:",
"@typescript-eslint/parser": "catalog:",
"@vitejs/plugin-react": "catalog:",
Expand Down Expand Up @@ -147,14 +146,14 @@
"clsx": "catalog:",
"cmdk": "1.1.1",
"color": "5.0.3",
"country-flag-icons": "catalog:",
"lucide-react": "catalog:",
"moment-timezone": "^0.5.48",
"react": "catalog:",
"react-day-picker": "9.14.0",
"react-dom": "catalog:",
"react-dropzone": "14.4.1",
"react-hook-form": "7.80.0",
"react-world-flags": "1.6.0",
"recharts": "2.15.4",
"sonner": "catalog:",
"tailwind-merge": "3.6.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/shade/src/components/ui/flag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const meta = {
parameters: {
docs: {
description: {
component: 'Display country flags using ISO country codes. Built on react-world-flags with customizable sizing and fallback support for invalid or missing country codes.'
component: 'Display country flags using ISO country codes. Built on country-flag-icons with customizable sizing and fallback support for invalid or missing country codes.'
}
}
},
Expand Down
28 changes: 19 additions & 9 deletions apps/shade/src/components/ui/flag.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {cn} from '@/lib/utils';
import React from 'react';
import ReactFlag from 'react-world-flags';
import {hasFlag} from 'country-flag-icons';
import * as Flags from 'country-flag-icons/react/3x2';

interface FlagProps {
width?: string;
Expand All @@ -10,6 +11,8 @@ interface FlagProps {
fallback?: React.ReactNode | null | undefined;
}

type FlagComponent = React.ComponentType<React.SVGProps<SVGSVGElement>>;

const Flag: React.FC<FlagProps> = ({
className,
countryCode,
Expand All @@ -22,17 +25,24 @@ const Flag: React.FC<FlagProps> = ({
height: height
};

const code = countryCode ? countryCode.toUpperCase() : '';
const FlagIcon = code && hasFlag(code) ? (Flags as Record<string, FlagComponent>)[code] : undefined;

const defaultFallback = fallback || <span className='h-[14px] w-[22px] rounded-[2px] bg-muted-foreground/20' style={sizeStyle}></span>;

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

fallback of null doesn't render nothing — it still falls back to the default placeholder.

FlagProps.fallback is typed as React.ReactNode | null | undefined, implying null is a distinct, intentional value (e.g. "render nothing"). But fallback || <span .../> treats null the same as undefined since both are falsy, so an explicit fallback={null} still renders the default muted placeholder instead of nothing.

🐛 Proposed fix distinguishing "not provided" from "explicitly empty"
-    const defaultFallback = fallback || <span className='h-[14px] w-[22px] rounded-[2px] bg-muted-foreground/20' style={sizeStyle}></span>;
+    const defaultFallback = fallback === undefined
+        ? <span className='h-[14px] w-[22px] rounded-[2px] bg-muted-foreground/20' style={sizeStyle}></span>
+        : fallback;
📝 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
const defaultFallback = fallback || <span className='h-[14px] w-[22px] rounded-[2px] bg-muted-foreground/20' style={sizeStyle}></span>;
const defaultFallback = fallback === undefined
? <span className='h-[14px] w-[22px] rounded-[2px] bg-muted-foreground/20' style={sizeStyle}></span>
: fallback;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/shade/src/components/ui/flag.tsx` at line 31, The fallback handling in
Flag is treating an explicit null the same as an omitted value, so
`fallback={null}` still renders the default placeholder. Update the `Flag`
component’s fallback selection logic to distinguish “not provided” from
“intentionally empty” by checking for `undefined` only, and preserve `null` as a
valid value that renders nothing. Use the existing `FlagProps.fallback` and
`defaultFallback` code path in `flag.tsx` to apply the fix.


return (
<div className={cn('relative flex items-center justify-center overflow-hidden rounded-[2px]', className)} style={sizeStyle}>
<ReactFlag
className='absolute w-auto max-w-none rounded-[2px]'
code={`${countryCode}`}
fallback={fallback || <span className='h-[14px] w-[22px] rounded-[2px] bg-muted-foreground/20' style={sizeStyle}></span>}
style={{
height: height
}} />
{FlagIcon
? (
<FlagIcon
className='absolute w-auto max-w-none rounded-[2px]'
style={{
height: height
}} />
)
: defaultFallback}
</div>
);
};

export {Flag};
export {Flag};
81 changes: 11 additions & 70 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ catalog:
chalk: 4.1.2
clsx: 2.1.1
concurrently: 10.0.3
country-flag-icons: 1.6.20
cross-fetch: 4.1.0
dequal: 2.0.3
dompurify: 3.4.11
Expand Down
Loading