📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fix: refresh timezone, scroll, and IP range edge cases
Blue Mouseccaa957242ff
diff --git a/backend/apps/cloud/src/common/ip-range.ts b/backend/apps/cloud/src/common/ip-range.tsindex 32dd1a269..805bedfd2 100644--- a/backend/apps/cloud/src/common/ip-range.ts+++ b/backend/apps/cloud/src/common/ip-range.ts@@ -5,6 +5,10 @@ interface ParsedIp {bytes: number[]}+interface ParseIpOptions {+ preserveIPv4Mapped?: boolean+}+const parseIPv4 = (address: string): number[] | null => {const parts = address.split('.')if (parts.length !== 4) return null@@ -75,7 +79,10 @@ const isIPv4MappedIPv6 = (bytes: number[]): boolean => {)}-const parseIp = (address: string): ParsedIp | null => {+const parseIp = (+ address: string,+ options: ParseIpOptions = {},+): ParsedIp | null => {const version = isIP(address)if (version === 4) {@@ -86,7 +93,7 @@ const parseIp = (address: string): ParsedIp | null => {if (version === 6) {const bytes = parseIPv6Bytes(address)if (!bytes) return null- if (isIPv4MappedIPv6(bytes)) {+ if (isIPv4MappedIPv6(bytes) && !options.preserveIPv4Mapped) {return { version: 4, bytes: bytes.slice(12) }}return { version: 6, bytes }@@ -123,7 +130,10 @@ const matchesSingleRange = (address: string, range: string): boolean => {const target = parseIp(address)if (!target) return false- const [rangeAddress, prefixText] = range.split('/')+ const rangeParts = range.split('/')+ if (rangeParts.length > 2) return false++ const [rangeAddress, prefixText] = rangePartsconst parsedRange = parseIp(rangeAddress)if (!parsedRange) return false@@ -136,7 +146,16 @@ const matchesSingleRange = (address: string, range: string): boolean => {}if (!/^\d+$/.test(prefixText)) return false- return matchesPrefix(target, parsedRange, Number(prefixText))+ if (matchesPrefix(target, parsedRange, Number(prefixText))) return true++ const targetAsIPv6 = parseIp(address, { preserveIPv4Mapped: true })+ const rangeAsIPv6 = parseIp(rangeAddress, { preserveIPv4Mapped: true })++ return !!(+ targetAsIPv6 &&+ rangeAsIPv6 &&+ matchesPrefix(targetAsIPv6, rangeAsIPv6, Number(prefixText))+ )}export const isIpInRange = (diff --git a/web/Dockerfile b/web/Dockerfileindex 1ee814bec..a130dc775 100644--- a/web/Dockerfile+++ b/web/Dockerfile@@ -46,6 +46,7 @@ COPY --from=production-deps /app/node_modules /app/node_modulesCOPY --from=build /app/build /app/buildCOPY --from=build /app/public /app/publicCOPY package*.json .npmrc ./-COPY start.cjs ./start.cjs+# start.cjs is for ecosystem.config.cjs/PM2; Docker runs npm start directly.+# Inject .env values through the Docker runtime.CMD ["npm", "run", "start"]diff --git a/web/app/pages/Project/tabs/AskAI/AskAIView.tsx b/web/app/pages/Project/tabs/AskAI/AskAIView.tsxindex 96a19189d..49f29eaca 100644--- a/web/app/pages/Project/tabs/AskAI/AskAIView.tsx+++ b/web/app/pages/Project/tabs/AskAI/AskAIView.tsx@@ -993,25 +993,23 @@ const ScrollToBottomButton = ({type='button'onClick={scrollToBottom}className='absolute bottom-32 left-1/2 z-30 flex h-10 w-10 -translate-x-1/2 items-center justify-center rounded-full bg-white text-gray-800 ring-1 ring-gray-200/80 transition-colors hover:bg-gray-50 focus:ring-2 focus:ring-slate-900 focus:outline-hidden dark:bg-slate-900 dark:text-gray-100 dark:ring-slate-700/80 dark:hover:bg-slate-800 dark:focus:ring-slate-300'- aria-label={- isStreaming- ? t('project.askAi.thinking')- : t('project.askAi.scrollToBottom')- }+ aria-label={t('project.askAi.scrollToBottom')}>+ <ArrowDownIcon className='h-5 w-5' />{isStreaming ? (- <span className='flex items-center gap-1'>+ <span+ className='absolute top-1.5 right-1.5 flex items-center gap-0.5'+ aria-hidden='true'+ >{[0, 1, 2].map((index) => (<spankey={index}- className='h-1.5 w-1.5 animate-bounce rounded-full bg-current'+ className='h-1 w-1 animate-bounce rounded-full bg-current'style={{ animationDelay: `${index * 120}ms` }}/>))}</span>- ) : (- <ArrowDownIcon className='h-5 w-5' />- )}+ ) : null}</button>)}@@ -1019,13 +1017,23 @@ const ScrollToBottomButton = ({const SCROLL_BOTTOM_THRESHOLD = 96const useChatScroll = () => {- const scrollRef = useRef<HTMLDivElement>(null)- const contentRef = useRef<HTMLDivElement>(null)+ const scrollElRef = useRef<HTMLDivElement | null>(null)+ const [scrollEl, setScrollEl] = useState<HTMLDivElement | null>(null)+ const [contentEl, setContentEl] = useState<HTMLDivElement | null>(null)const isAtBottomRef = useRef(true)const [isAtBottom, setIsAtBottom] = useState(true)+ const scrollRef = useCallback((node: HTMLDivElement | null) => {+ scrollElRef.current = node+ setScrollEl(node)+ }, [])++ const contentRef = useCallback((node: HTMLDivElement | null) => {+ setContentEl(node)+ }, [])+const updateIsAtBottom = useCallback(() => {- const scrollEl = scrollRef.current+ const scrollEl = scrollElRef.currentif (!scrollEl) returnconst distanceFromBottom =@@ -1039,7 +1047,7 @@ const useChatScroll = () => {}, [])const scrollToBottom = useCallback((behavior: ScrollBehavior = 'smooth') => {- const scrollEl = scrollRef.current+ const scrollEl = scrollElRef.currentif (!scrollEl) returnscrollEl.scrollTo({@@ -1050,8 +1058,9 @@ const useChatScroll = () => {setIsAtBottom(true)}, [])+ const isPinnedToBottom = useCallback(() => isAtBottomRef.current, [])+useEffect(() => {- const scrollEl = scrollRef.currentif (!scrollEl) returnupdateIsAtBottom()@@ -1060,13 +1069,14 @@ const useChatScroll = () => {return () => {scrollEl.removeEventListener('scroll', updateIsAtBottom)}- }, [updateIsAtBottom])+ }, [scrollEl, updateIsAtBottom])return {scrollRef,contentRef,+ contentEl,isAtBottom,- isAtBottomRef,+ isPinnedToBottom,scrollToBottom,}}@@ -1841,8 +1851,14 @@ const AskAIView = ({ projectId }: AskAIViewProps) => {const isLoadingChats = allChatsFetcher.state !== 'idle'- const { scrollRef, contentRef, isAtBottom, isAtBottomRef, scrollToBottom } =- useChatScroll()+ const {+ scrollRef,+ contentRef,+ contentEl,+ isAtBottom,+ isPinnedToBottom,+ scrollToBottom,+ } = useChatScroll()const streamingContentRef = useRef('')const streamingReasoningRef = useRef('')@@ -2857,7 +2873,7 @@ const AskAIView = ({ projectId }: AskAIViewProps) => {const isChatActive = !isEmptyuseEffect(() => {- if (!isChatActive || !isAtBottomRef.current) return+ if (!isChatActive || !isPinnedToBottom()) returnconst frame = window.requestAnimationFrame(() => {scrollToBottom('auto')@@ -2869,10 +2885,38 @@ const AskAIView = ({ projectId }: AskAIViewProps) => {streamingMessage,isWaitingForResponse,isChatActive,- isAtBottomRef,+ isPinnedToBottom,scrollToBottom,])+ useEffect(() => {+ if (!isChatActive || !contentEl || typeof ResizeObserver === 'undefined') {+ return+ }++ let frame: number | null = null+ const scrollPinnedChat = () => {+ if (!isPinnedToBottom()) return+ if (frame !== null) {+ window.cancelAnimationFrame(frame)+ }+ frame = window.requestAnimationFrame(() => {+ frame = null+ scrollToBottom('auto')+ })+ }++ const observer = new ResizeObserver(scrollPinnedChat)+ observer.observe(contentEl)++ return () => {+ if (frame !== null) {+ window.cancelAnimationFrame(frame)+ }+ observer.disconnect()+ }+ }, [contentEl, isChatActive, isPinnedToBottom, scrollToBottom])+const formatRelativeTime = useCallback((dateStr: string) => {const date = new Date(dateStr)diff --git a/web/app/ui/TimezonePicker.tsx b/web/app/ui/TimezonePicker.tsxindex 8bd5bd70f..3ae89edb8 100644--- a/web/app/ui/TimezonePicker.tsx+++ b/web/app/ui/TimezonePicker.tsx@@ -6,10 +6,21 @@ import timezones from '~/lib/constants/timezones'import Select from './Select'-const date = new Date()+interface TimezoneOption {+ value: string+ label: string+ offset: number+ abbrev?: string+ altName?: string+}-const getTimezoneOffsetMinutes = (timeZone: string): number => {+const getTimezoneOffsetMinutes = (+ timeZone: string,+ referenceDate: Date,+): number => {try {+ const date = new Date(referenceDate)+ date.setMilliseconds(0)const parts = new Intl.DateTimeFormat('en-US', {timeZone,hour12: false,@@ -44,6 +55,7 @@ const getTimezoneOffsetMinutes = (timeZone: string): number => {const getTimezoneName = (timeZone: string,timeZoneName: 'short' | 'long',+ date: Date,): string | undefined => {try {return new Intl.DateTimeFormat('en-US', {@@ -66,39 +78,42 @@ const formatOffset = (offsetMinutes: number): string => {return `${sign}${hours}:${String(minutes).padStart(2, '0')}`}-const options = _reduce(- Object.entries(timezones),- (selectOptions: any[], zone) => {- const offsetMinutes = getTimezoneOffsetMinutes(zone[0])- const hr = formatOffset(offsetMinutes)- const label = `(GMT${_includes(hr, '-') ? hr : `+${hr}`}) ${zone[1]}`-- selectOptions.push({- value: zone[0],- label,- offset: offsetMinutes / 60,- abbrev: getTimezoneName(zone[0], 'short'),- altName: getTimezoneName(zone[0], 'long'),- })-- return selectOptions- },- [],-).sort((a, b) => a.offset - b.offset)+const buildOptions = (date = new Date()) =>+ _reduce(+ Object.entries(timezones),+ (selectOptions: TimezoneOption[], zone) => {+ const offsetMinutes = getTimezoneOffsetMinutes(zone[0], date)+ const hr = formatOffset(offsetMinutes)+ const label = `(GMT${_includes(hr, '-') ? hr : `+${hr}`}) ${zone[1]}`++ selectOptions.push({+ value: zone[0],+ label,+ offset: offsetMinutes / 60,+ abbrev: getTimezoneName(zone[0], 'short', date),+ altName: getTimezoneName(zone[0], 'long', date),+ })++ return selectOptions+ },+ [],+ ).sort((a, b) => a.offset - b.offset)interface TimezoneSelectProps {value:| string| {value: string- label: string+ label?: string}onChange: (item: string) => void}const TimezoneSelect = ({ value, onChange }: TimezoneSelectProps) => {- const labelExtractor = (option: { label: string }) => option?.label- const keyExtractor = (option: { value: string }) => option?.value+ const options = buildOptions()+ const labelExtractor = (option: TimezoneOption | null | undefined) =>+ option?.label+ const keyExtractor = (option: TimezoneOption) => option.valueconst handleChange = (item: any) => {const key = keyExtractor(item)@@ -110,35 +125,42 @@ const TimezoneSelect = ({ value, onChange }: TimezoneSelectProps) => {| string| {value: string- label: string+ label?: string},- ) => {+ ): TimezoneOption | null => {if (typeof zone === 'object' && zone.value && zone.label) {- return zone+ return (+ _find(options, (tz) => tz.value === zone.value) ?? {+ value: zone.value,+ label: zone.label,+ offset: 0,+ }+ )}if (typeof zone === 'string') {- return _find(options, (tz) => tz.value === zone)+ return _find(options, (tz) => tz.value === zone) ?? null}if (zone.value && !zone.label) {- return _find(options, (tz) => tz.value === zone.value)+ return _find(options, (tz) => tz.value === zone.value) ?? null}return null}+ const selectedTimezone = parseTimezone(value)+return (<Select- title={labelExtractor(parseTimezone(value))}+ title={labelExtractor(selectedTimezone)}className='w-full'items={options}labelExtractor={labelExtractor}- // @ts-expect-errorkeyExtractor={keyExtractor}onSelect={handleChange}capitalise- selectedItem={parseTimezone(value)}+ selectedItem={selectedTimezone ?? undefined}/>)}diff --git a/web/app/utils/download.ts b/web/app/utils/download.tsindex 0279bc279..3729c4d9d 100644--- a/web/app/utils/download.ts+++ b/web/app/utils/download.ts@@ -6,7 +6,7 @@ export const downloadBlob = (blob: Blob, filename: string) => {document.body.appendChild(anchor)anchor.click()document.body.removeChild(anchor)- setTimeout(() => URL.revokeObjectURL(url), 0)+ setTimeout(() => URL.revokeObjectURL(url), 150)}export const downloadText = (