-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev #224
Conversation
WalkthroughThe changes involve modifications to multiple components related to the announcement feature in the header. The Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
app/modules/predictive-search/predictive-search-results.tsx (3)
Line range hint
14-26
: Consider preserving native link behavior for non-suggestion resultsThe current implementation prevents default behavior for all links and then manually navigates using
window.location.href
. This breaks native browser features like opening links in new tabs (middle-click/right-click).Consider conditionally preventing default behavior:
function goToSearchResult(event: React.MouseEvent<HTMLAnchorElement>) { - event.preventDefault(); let type = event.currentTarget.dataset.type; if (!searchInputRef.current) return; if (type === "SearchQuerySuggestion") { + event.preventDefault(); searchInputRef.current.value = event.currentTarget.innerText; // dispatch event onchange for the search searchInputRef.current.focus(); } else { searchInputRef.current.blur(); searchInputRef.current.value = ""; - // close the aside - window.location.href = event.currentTarget.href; } }
Line range hint
77-84
: Remove commented-out codeKeeping commented-out code can lead to confusion and maintenance issues. If this is an alternative implementation, consider:
- Removing it if it's no longer needed
- Creating a separate component if both implementations might be needed
- Using a feature flag if this is meant for A/B testing
Line range hint
43-76
: Consider component decomposition for better maintainabilityThe search results section contains complex layout logic mixed with business logic. Consider:
- Extracting each result section (queries, articles, products) into separate components
- Making the grid layout more responsive using dynamic values instead of fixed dimensions
- Using CSS Grid's auto-fit/auto-fill for better responsiveness
Example structure:
// SearchResultsSection.tsx interface SearchResultsSectionProps { title: string; items: any[]; onResultClick: (event: React.MouseEvent<HTMLAnchorElement>) => void; } function SearchResultsSection({ title, items, onResultClick }: SearchResultsSectionProps) { return ( <div className="flex flex-col gap-4"> <h2>{title}</h2> <PredictiveSearchResult goToSearchResult={onResultClick} items={items} type={title.toLowerCase()} /> </div> ); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (3)
app/modules/header/scrolling-announcement.tsx (1)
4-4
: Add documentation for the MAX_DURATION constantConsider adding a comment explaining what MAX_DURATION represents and why it's set to 20. This will help other developers understand its purpose in controlling the animation speed.
+// Maximum duration (in seconds) for the scrolling animation at speed 1 const MAX_DURATION = 20;
tailwind.config.js (1)
58-58
: Consider adding a fallback durationWhile the 15s duration is more appropriate for reading announcements, consider adding a reasonable fallback duration in case the CSS variable is not set:
- marquee: "marquee var(--marquee-duration, 15s) linear infinite", + marquee: "marquee clamp(5s, var(--marquee-duration, 15s), 30s) linear infinite",This ensures:
- A minimum duration of 5s for short content
- A maximum duration of 30s for very long content
- Default of 15s when the variable is set
app/weaverse/schema.server.ts (1)
Line range hint
142-185
: Consider documenting the new scrolling speed implementationThe change from seconds to a multiplier-based speed configuration represents a significant shift in the animation implementation. Consider:
- Adding documentation explaining how the multiplier affects scrolling speed
- Including examples of typical values (e.g., what speed to expect at 1x vs 20x)
- Documenting why the maximum was reduced from 100 to 20
This will help other developers understand and correctly utilize the new configuration.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
app/modules/header/announcement-bar.tsx
(0 hunks)app/modules/header/index.tsx
(2 hunks)app/modules/header/marquee.tsx
(0 hunks)app/modules/header/scrolling-announcement.tsx
(1 hunks)app/weaverse/schema.server.ts
(3 hunks)tailwind.config.js
(2 hunks)
💤 Files with no reviewable changes (2)
- app/modules/header/announcement-bar.tsx
- app/modules/header/marquee.tsx
🔇 Additional comments (9)
app/modules/header/scrolling-announcement.tsx (2)
35-37
: LGTM!
The conditional rendering is implemented correctly and follows React best practices.
1-65
: Verify removal of old AnnouncementBar references
Since this component replaces the old AnnouncementBar, we should verify that all references to the old component have been updated.
✅ Verification successful
No remaining references to old AnnouncementBar component found
Based on the comprehensive search results:
- The new
ScrollingAnnouncement
component is properly integrated inapp/modules/header/index.tsx
- Other files containing "announcement" references (
schema.server.ts
,slide.tsx
, andhero-image.tsx
) only contain the word in different contexts (content placeholders and configuration) - No imports or usage of the old
AnnouncementBar
component were found in the codebase
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining references to the old AnnouncementBar component
rg -l "AnnouncementBar"
# Search for any imports of the old component
ast-grep --pattern 'import { $$$AnnouncementBar$$$ } from "$_"'
Length of output: 89
Script:
#!/bin/bash
# Let's try a more comprehensive search for any references to announcement bar
# Search for files containing "announcement" case-insensitive
rg -il "announcement"
# Also search for potential kebab-case or pascal-case variations
rg -il "announcement-bar|AnnouncementBar"
# Look for any component imports with "announcement" in the name
ast-grep --pattern 'import { $$$announcement$$$ } from "$_"'
Length of output: 340
Script:
#!/bin/bash
# Let's check the content of these files to understand the context
echo "=== Checking header/index.tsx ==="
cat app/modules/header/index.tsx
echo -e "\n=== Checking schema.server.ts ==="
cat app/weaverse/schema.server.ts
echo -e "\n=== Checking sections with announcement references ==="
cat app/sections/slideshow/slide.tsx
cat app/sections/hero-image.tsx
Length of output: 32943
app/modules/header/index.tsx (3)
7-7
: LGTM! Import statements are properly organized and utilized.
The new imports are correctly structured and all imported entities are used within the component.
Also applies to: 12-13
46-46
: Verify ScrollingAnnouncement configuration
The component is rendered without props. Let's verify if it's properly configured through theme settings or context.
✅ Verification successful
ScrollingAnnouncement is properly configured through theme settings
The component implementation shows it correctly uses the useThemeSettings
hook to access necessary configuration like topbarText
, topbarHeight
, topbarTextColor
, and other related settings. The component handles its own configuration internally, so rendering it without props is the correct approach.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if ScrollingAnnouncement accepts any props in its implementation
ast-grep --pattern 'export function ScrollingAnnouncement($_) {
$$$
}'
# Check for any theme configuration usage
rg -A 5 "ScrollingAnnouncement" ./app/modules/header/scrolling-announcement.tsx
Length of output: 301
Script:
#!/bin/bash
# Let's check the full implementation to understand how theme settings are used
rg -A 15 "export function ScrollingAnnouncement" ./app/modules/header/scrolling-announcement.tsx
# Check if there are any required theme settings
rg "topbarText|topbarHeight|topbarTextColor" ./app/modules/theme
Length of output: 638
Script:
#!/bin/bash
# Let's find where theme settings are defined
fd theme --type f --exec rg -l "topbarText|topbarHeight|topbarTextColor" {}
# Check the useThemeSettings hook implementation
ast-grep --pattern 'export function useThemeSettings() {
$$$
}'
Length of output: 147
Line range hint 15-53
: Consider theme customization implications
The transition from AnnouncementBar to ScrollingAnnouncement maintains clean component architecture. However, ensure that all theme customization capabilities previously available in AnnouncementBar are preserved or properly migrated to the new ScrollingAnnouncement component.
✅ Verification successful
Theme customization is properly maintained
The ScrollingAnnouncement component fully preserves theme customization capabilities through the useThemeSettings
hook. It supports all necessary theme properties:
- Text content (
topbarText
) - Height (
topbarHeight
) - Text color (
topbarTextColor
) - Background color (
topbarBgColor
) - Scrolling gap (
topbarScrollingGap
) - Scrolling speed (
topbarScrollingSpeed
)
The component maintains clean architecture while providing even more customization options than before, making it a proper enhancement rather than a concern.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check for theme-related configurations
rg -A 5 "announcement" ./app/theme
Length of output: 86
Script:
#!/bin/bash
# Let's search for announcement-related components and configurations across the codebase
rg -l "ScrollingAnnouncement|AnnouncementBar" --type tsx --type ts
# Check the implementation of ScrollingAnnouncement
fd "ScrollingAnnouncement" --type f --exec cat {}
Length of output: 148
Script:
#!/bin/bash
# Search for announcement-related files without type restriction
rg -l "ScrollingAnnouncement|AnnouncementBar"
# Also search for any theme or customization related code near announcements
rg -B 3 -A 3 "ScrollingAnnouncement|AnnouncementBar"
Length of output: 1554
Script:
#!/bin/bash
# Let's examine the ScrollingAnnouncement implementation and theme settings
cat app/modules/header/scrolling-announcement.tsx
# Also check for useThemeSettings implementation
rg -B 2 -A 5 "useThemeSettings"
Length of output: 16177
tailwind.config.js (1)
36-37
: Great performance optimization using 3D transforms!
The switch to translate3d
and translateZ(0)
is a solid improvement as it:
- Triggers hardware acceleration for smoother animations
- Creates a new compositing layer to prevent text blur
- Maintains better performance during animation
app/weaverse/schema.server.ts (3)
142-143
: Group name change reflects new scrolling announcement implementation
The renaming from "Announcement bar" to "Scrolling announcements" aligns with the architectural changes mentioned in the AI summary, where AnnouncementBar
is replaced with ScrollingAnnouncement
.
Line range hint 153-161
: Verify the impact of renamed configuration property
The configuration property has been renamed from scrollingGap
to topbarScrollingGap
. While the configuration values remain unchanged, ensure this rename is reflected in all components consuming this configuration.
✅ Verification successful
Configuration property rename is properly reflected in the codebase
The configuration property rename from scrollingGap
to topbarScrollingGap
has been properly implemented. The search results show:
- No remaining references to the old
scrollingGap
name - The new
topbarScrollingGap
is correctly defined inschema.server.ts
- The new name is properly consumed in
scrolling-announcement.tsx
component
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining references to the old configuration name
rg "scrollingGap" --type ts --type tsx
# Search for usage of the new configuration name
rg "topbarScrollingGap" --type ts --type tsx
Length of output: 139
Script:
#!/bin/bash
# Search for any remaining references to the old configuration name without file type restrictions
rg "scrollingGap"
# Search for usage of the new configuration name without file type restrictions
rg "topbarScrollingGap"
Length of output: 271
177-185
: Review changes to scrolling speed configuration
Several significant changes to the scrolling speed configuration:
- Property renamed from
scrollingSpeed
totopbarScrollingSpeed
- Range adjusted from 0-100 to 1-20
- Unit changed from "s" to "x"
- Default value reduced from 10 to 5
These changes suggest a fundamental shift in how scrolling speed is calculated. Please verify:
- The new range (1-20x) provides appropriate control over scrolling speed
- The minimum value of 1x makes sense as a lower bound
- Components are updated to handle the unit change from seconds to multiplier
✅ Verification successful
Review changes to scrolling speed configuration - Verified
The changes to the scrolling speed configuration are appropriate and well-implemented:
- The new range of 1-20x makes sense as it directly maps to the animation duration through the formula
MAX_DURATION / topbarScrollingSpeed
, whereMAX_DURATION
is 20 seconds - A minimum value of 1x results in the slowest animation (20s duration), while 20x results in the fastest animation (1s duration)
- The unit change from "s" to "x" better reflects that the value is a multiplier of the base speed
- The default value of 5x results in a 4-second animation duration, which is reasonable for readable scrolling text
The implementation in the ScrollingAnnouncement component correctly applies these values to control the CSS animation duration.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for components using the scrolling speed configuration
rg "topbarScrollingSpeed|scrollingSpeed" --type tsx -A 5
# Look for any animation-related code that might be affected
ast-grep --pattern 'animation: $_ $_'
Length of output: 126
Script:
#!/bin/bash
# Search for components using the scrolling speed configuration with broader file types
rg "topbarScrollingSpeed|scrollingSpeed" -t ts -t js -t jsx -t tsx -A 5
# Look for files that might contain animation or scroll-related code
rg "animation|scroll" -t ts -t js -t jsx -t tsx -A 5
# Search for schema or configuration files that might reference these settings
fd "schema|config" -e ts -e js -e json --exec cat {}
Length of output: 30571
Script:
#!/bin/bash
# Search for scrolling-related code in the entire codebase
rg "scroll|animation" -g "!*.{json,config.js}" -A 5
# Look for any CSS/Tailwind animation configurations
rg "marquee|animation" app/styles -A 5
# Search for any React components that might use the scrolling speed
fd -e tsx -e jsx -e ts -e js . -x cat {}
Length of output: 107005
Script:
#!/bin/bash
# Search for scrolling announcement component implementation
rg -t ts -t tsx -t js "ScrollingAnnouncement" -A 10
# Look for any CSS animations related to scrolling announcements
rg -t css "marquee|scroll" -A 5 app/styles
# Search for any theme or configuration files that might use the scrolling speed
rg "topbarScrollingSpeed|scrollingSpeed" -t ts -t js -g "!*.d.ts"
Length of output: 1136
Script:
#!/bin/bash
# Get the content of the scrolling announcement component to understand the implementation
cat app/modules/header/scrolling-announcement.tsx
# Look for any constants or utility files that might define MAX_DURATION
rg "MAX_DURATION" -A 2 -B 2
Length of output: 2651
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation> | ||
useEffect(() => { | ||
updateStyles(); | ||
window.addEventListener("scroll", updateStyles); | ||
return () => window.removeEventListener("scroll", updateStyles); | ||
}, [topbarText]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incomplete useEffect dependency array
The effect's dependency array is missing topbarHeight
, which could lead to stale closures. Also, the lint ignore comment should explain why dependencies are being ignored.
- // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
+ // biome-ignore lint/correctness/useExhaustiveDependencies: topbarHeight changes would cause unnecessary re-subscriptions
useEffect(() => {
updateStyles();
window.addEventListener("scroll", updateStyles);
return () => window.removeEventListener("scroll", updateStyles);
- }, [topbarText]);
+ }, [topbarText, topbarHeight, updateStyles]);
Committable suggestion skipped: line range outside the PR's diff.
export function ScrollingAnnouncement() { | ||
let themeSettings = useThemeSettings(); | ||
let { | ||
topbarText, | ||
topbarHeight, | ||
topbarTextColor, | ||
topbarBgColor, | ||
topbarScrollingGap, | ||
topbarScrollingSpeed, | ||
} = themeSettings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add TypeScript types for theme settings
The theme settings are currently untyped, which could lead to runtime errors if the values are undefined or of unexpected types. Consider adding proper TypeScript interfaces and default values.
+interface ThemeSettings {
+ topbarText?: string;
+ topbarHeight: number;
+ topbarTextColor: string;
+ topbarBgColor: string;
+ topbarScrollingGap: number;
+ topbarScrollingSpeed: number;
+}
export function ScrollingAnnouncement() {
- let themeSettings = useThemeSettings();
+ let themeSettings = useThemeSettings() as ThemeSettings;
let {
topbarText,
topbarHeight = 40, // Add default value
topbarTextColor = '#000000',
topbarBgColor = '#ffffff',
topbarScrollingGap = 20,
topbarScrollingSpeed = 1,
} = themeSettings;
📝 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.
export function ScrollingAnnouncement() { | |
let themeSettings = useThemeSettings(); | |
let { | |
topbarText, | |
topbarHeight, | |
topbarTextColor, | |
topbarBgColor, | |
topbarScrollingGap, | |
topbarScrollingSpeed, | |
} = themeSettings; | |
interface ThemeSettings { | |
topbarText?: string; | |
topbarHeight: number; | |
topbarTextColor: string; | |
topbarBgColor: string; | |
topbarScrollingGap: number; | |
topbarScrollingSpeed: number; | |
} | |
export function ScrollingAnnouncement() { | |
let themeSettings = useThemeSettings() as ThemeSettings; | |
let { | |
topbarText, | |
topbarHeight = 40, | |
topbarTextColor = '#000000', | |
topbarBgColor = '#ffffff', | |
topbarScrollingGap = 20, | |
topbarScrollingSpeed = 1, | |
} = themeSettings; |
function updateStyles() { | ||
if (topbarText) { | ||
document.body.style.setProperty( | ||
"--topbar-height", | ||
`${Math.max(topbarHeight - window.scrollY, 0)}px`, | ||
); | ||
} else { | ||
document.body.style.setProperty("--topbar-height", "0px"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Optimize scroll performance and handle SSR
The current implementation has two potential issues:
- Direct DOM manipulation might cause hydration mismatches during SSR
- Frequent style updates on scroll could impact performance
Consider these improvements:
+import { useCallback } from 'react';
+import debounce from 'lodash/debounce';
export function ScrollingAnnouncement() {
+ const updateStyles = useCallback(
+ debounce(() => {
+ if (typeof document === 'undefined') return;
if (topbarText) {
document.body.style.setProperty(
"--topbar-height",
`${Math.max(topbarHeight - window.scrollY, 0)}px`,
);
} else {
document.body.style.setProperty("--topbar-height", "0px");
}
+ }, 16),
+ [topbarText, topbarHeight]
+ );
Committable suggestion skipped: line range outside the PR's diff.
return ( | ||
<div | ||
id="announcement-bar" | ||
className="text-center z-50 relative flex items-center whitespace-nowrap" | ||
style={ | ||
{ | ||
height: `${topbarHeight}px`, | ||
backgroundColor: topbarBgColor, | ||
color: topbarTextColor, | ||
"--marquee-duration": `${MAX_DURATION / topbarScrollingSpeed}s`, | ||
"--gap": `${topbarScrollingGap}px`, | ||
} as React.CSSProperties | ||
} | ||
> | ||
{new Array(10).fill("").map((_, idx) => { | ||
return ( | ||
<div className="animate-marquee px-[calc(var(--gap)/2)]" key={idx}> | ||
<div | ||
className="flex items-center gap-[--gap] whitespace-nowrap [&_p]:flex [&_p]:gap-2 [&_p]:items-center" | ||
dangerouslySetInnerHTML={{ __html: topbarText }} | ||
/> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address security and accessibility concerns
Several issues need attention:
- Using
dangerouslySetInnerHTML
with unvalidated content poses an XSS risk - The announcement bar lacks proper ARIA attributes
- Hard-coded array length might not work for all screen sizes
Consider these improvements:
<div
id="announcement-bar"
- className="text-center z-50 relative flex items-center whitespace-nowrap"
+ className="text-center z-50 relative flex items-center whitespace-nowrap overflow-hidden"
+ role="alert"
+ aria-live="polite"
style={/* ... */}
>
- {new Array(10).fill("").map((_, idx) => {
+ {new Array(Math.ceil(window.innerWidth / 300) + 2).fill("").map((_, idx) => {
return (
<div className="animate-marquee px-[calc(var(--gap)/2)]" key={idx}>
<div
className="flex items-center gap-[--gap] whitespace-nowrap [&_p]:flex [&_p]:gap-2 [&_p]:items-center"
- dangerouslySetInnerHTML={{ __html: topbarText }}
- />
+ >
+ {/* Replace dangerouslySetInnerHTML with a sanitized alternative */}
+ <div>{sanitizeHtml(topbarText)}</div>
+ </div>
</div>
);
})}
</div>
Also, consider adding a dependency:
+import sanitizeHtml from 'sanitize-html';
Committable suggestion skipped: line range outside the PR's diff.
Summary by CodeRabbit
Bug Fixes
New Features
Chores