Honor the share-link miss limit before querying, and keep Escape inside the access menu.

This commit is contained in:
adilallo committed 2026-11-21 11:56:34 -07:00
1 parent 75649a9a42
commit 1b3d055c81
8 files changed
+189 -19

No files matched your search

+9 -2
View File
@@ -3,7 +3,10 @@ import { headers } from "next/headers";
import { notFound } from "next/navigation";
import messages from "../../../../messages/en/index";
import { isShareSlug } from "../../../../lib/sharePaths";
import { getReadablePublishedRule } from "../../../../lib/server/publishedRules";
import {
SHARE_LOOKUP_MISS_INTERVAL_MS,
getReadablePublishedRule,
} from "../../../../lib/server/publishedRules";
import { rateLimitKey } from "../../../../lib/server/rateLimit";
import { getSessionUser } from "../../../../lib/server/session";
import { parsePublishedDocumentForCommunityRuleDisplay } from "../../../../lib/create/publishedDocumentToDisplaySections";
@@ -27,7 +30,11 @@ async function clientIp(): Promise<string> {
async function loadSharedRule(shareSlug: string) {
const ip = await clientIp();
if (!isShareSlug(shareSlug)) {
rateLimitKey(`share-lookup-miss:${ip}`, 1_000);
const limited = rateLimitKey(
`share-lookup-miss:${ip}`,
SHARE_LOOKUP_MISS_INTERVAL_MS,
);
if (!limited.ok) return null;
return null;
}
const user = await getSessionUser();
@@ -260,6 +260,9 @@ const SelectInputContainer = forwardRef<HTMLButtonElement, SelectInputProps>(
return;
}
if (e.key === "Escape") {
if (!isOpen) return;
e.preventDefault();
e.stopPropagation();
closeMenu();
}
},
@@ -287,14 +290,23 @@ const SelectInputContainer = forwardRef<HTMLButtonElement, SelectInputProps>(
}
}, [disabled, shouldAutoManageFocus]);
// Handle blur
const handleBlur = useCallback(() => {
if (shouldAutoManageFocus) {
setIsFocused(false);
setFocusMethod(null);
wasMouseDownRef.current = false;
}
}, [shouldAutoManageFocus]);
const handleMenuMouseDown = useCallback((event: React.MouseEvent) => {
event.preventDefault();
}, []);
const handleBlur = useCallback(
(event: React.FocusEvent<HTMLButtonElement>) => {
if (shouldAutoManageFocus) {
setIsFocused(false);
setFocusMethod(null);
wasMouseDownRef.current = false;
}
const next = event.relatedTarget;
if (next instanceof Node && menuRef.current?.contains(next)) return;
closeMenu();
},
[closeMenu, shouldAutoManageFocus],
);
// Determine actual state:
// - Active: when clicked (mouse focus) or when dropdown is open
@@ -362,6 +374,7 @@ const SelectInputContainer = forwardRef<HTMLButtonElement, SelectInputProps>(
onButtonMouseDown={handleMouseDown}
onButtonFocus={handleFocus}
onButtonBlur={handleBlur}
onMenuMouseDown={handleMenuMouseDown}
onOptionClick={handleOptionSelect}
selectRef={selectRef}
menuRef={menuRef}
@@ -26,7 +26,8 @@ export interface SelectInputViewProps {
onButtonKeyDown: (_e: React.KeyboardEvent<HTMLButtonElement>) => void;
onButtonMouseDown?: () => void;
onButtonFocus?: () => void;
onButtonBlur?: () => void;
onButtonBlur?: (_event: React.FocusEvent<HTMLButtonElement>) => void;
onMenuMouseDown?: (_event: React.MouseEvent<HTMLDivElement>) => void;
onOptionClick: (_value: string, _text: string) => void;
// Refs
selectRef: React.RefObject<HTMLButtonElement>;
@@ -67,6 +68,7 @@ export function SelectInputView({
onButtonMouseDown,
onButtonFocus,
onButtonBlur,
onMenuMouseDown,
onOptionClick,
selectRef,
menuRef,
@@ -257,6 +259,7 @@ export function SelectInputView({
ref={menuRef}
className="fixed z-[10050]"
style={menuStyle}
onMouseDown={onMenuMouseDown}
>
<SelectDropdown id={listboxId} ariaLabel={selectAriaLabel}>
{optionEntries.map((option, index) => (