Skip to content

drop preview url fix#1556

Merged
ragnep merged 4 commits intomainfrom
drop-preview-fix
Oct 21, 2025
Merged

drop preview url fix#1556
ragnep merged 4 commits intomainfrom
drop-preview-fix

Conversation

@ragnep
Copy link
Copy Markdown
Contributor

@ragnep ragnep commented Oct 21, 2025

Summary by CodeRabbit

  • New Features

    • Improved URL normalization for links so in-app links render consistently and respect the app's base origin.
  • Bug Fixes

    • More reliable extraction of referenced drop IDs with stronger origin validation.
    • Safer handling and fallbacks for malformed or cross-origin links to avoid broken previews.
  • Tests

    • Enhanced test helpers and mocks to simulate current-location context.
    • Added tests for root and cross-path link normalization.

Signed-off-by: ragnep <ragneinfo@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 21, 2025

Walkthrough

Adds URL normalization and base-origin validation for Seize links: introduces ensureStableSeizeLink and getSeizeBaseOrigin, updates handlers to use stable hrefs and URL-origin-based drop-id extraction, expands tests and test mocks, and changes DropItemChat signature to accept href.

Changes

Cohort / File(s) Summary
SeizeLinkParser Core
helpers/SeizeLinkParser.ts
Adds cached base URL helpers (getBaseUrl, getSeizeBaseOrigin), extends SeizeQuoteLinkInfo with optional dropId, refactors parseSeizeQueryLink to validate/resolve against base origin, and adds ensureStableSeizeLink(href, currentHref?).
Seize Link Handlers
components/drops/view/part/dropPartMarkdown/handlers/seize.tsx, components/drops/view/part/dropPartMarkdown/linkHandlers.tsx
Use ensureStableSeizeLink to produce stableHref; derive dropId via URL constructed with getSeizeBaseOrigin; switch matching/rendering flows (anchor/OpenGraph/preview/isSmartLink) to operate on stableHref with added parse-origin checks and error-safe fallbacks.
Tests — SeizeLinkParser
__tests__/helpers/SeizeLinkParser.test.ts
New tests exercising ensureStableSeizeLink behaviors: resolving relative links against base origin, preserving/replacing query params, rebasing across paths, handling non-parsable inputs, and base-endpoint change scenarios.
Tests — Link Handlers Registry & Mocks
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
Updates DropItemChat mock to accept href and render data-href; introduces a test wrapper/mock for ensureStableSeizeLink that delegates to real implementation with __setCurrentHref test setter; adds tests validating normalization using a controllable current href.
Component API change
@/components/waves/drops/DropItemChat
DropItemChat default export signature changed from ({ dropId }: { dropId: string }) to ({ dropId, href }: { dropId: string; href: string }) (tests updated to reflect this).

Sequence Diagram(s)

sequenceDiagram
    participant Handler as Link Handler
    participant SeizeLP as SeizeLinkParser
    participant Cache as Base URL Cache
    participant URL as URL constructor

    Handler->>SeizeLP: ensureStableSeizeLink(href, currentHref?)
    SeizeLP->>Cache: getSeizeBaseOrigin()
    Cache-->>SeizeLP: baseOrigin or null

    alt baseOrigin available
        SeizeLP->>URL: new URL(href, baseOrigin)
        URL-->>SeizeLP: parsed URL (origin, pathname, searchParams)
        SeizeLP->>SeizeLP: preserve/drop query params, align with currentHref if provided
        SeizeLP-->>Handler: stableHref (absolute, baseOrigin)
    else baseOrigin missing or parse fail
        SeizeLP-->>Handler: fallback href (original/current)
    end

    Handler->>Handler: use stableHref for matching (seize/external/internal) and rendering (anchor/open-graph/preview)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Fix process.env use #1495 — Modifies helpers/SeizeLinkParser.ts around BASE_ENDPOINT/origin handling and URL parsing; strongly related to base-origin derivation and parsing changes here.

Suggested reviewers

  • analyticsflowee

Poem

🐰 I hopped through links both near and far,

Anchors steady now, no shaky star,
Drop IDs found where paths rearrange,
Tests set the map and mocks let me change,
A tiny rabbit, making URLs less strange 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "drop preview url fix" is directly related to the main change in this pull request. The changeset introduces a new utility function ensureStableSeizeLink that normalizes and stabilizes URLs used in drop preview rendering, addressing URL parsing and consistency issues throughout the link handling pipeline. The title accurately captures the essence of the fix at the appropriate level of abstraction, and a teammate scanning the repository history would understand this PR addresses problems with drop preview URL handling. The title is concise, clear, and meaningfully describes the primary change without being overly vague.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch drop-preview-fix

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.

Copy link
Copy Markdown

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

🧹 Nitpick comments (3)
__tests__/helpers/SeizeLinkParser.test.ts (1)

85-152: Good coverage for URL normalization; add a hash case

Add a test asserting that URL fragments (hash) are preserved when rewriting (e.g., current https://site.com/messages#top + incoming /?drop=abc ⇒ ...?drop=abc#top).

components/drops/view/part/dropPartMarkdown/handlers/seize.tsx (1)

95-109: Safer dropId extraction with origin check — LGTM

Switch to URL parsing with getSeizeBaseOrigin() is correct and resilient. Optional follow-up: avoid double extraction by caching extract(href) between match/render if this becomes hot.

helpers/SeizeLinkParser.ts (1)

40-49: Align parseSeizeQuoteLink with the public type; parse via URL

The interface exposes optional dropId, but regex parsing never captures it. Prefer URL-based parsing with optional drop extraction for consistency and resilience.

Apply this diff:

-export function parseSeizeQuoteLink(href: string): SeizeQuoteLinkInfo | null {
-  const regex =
-    /\/waves\?wave=([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})&serialNo=(\d+)$/;
-
-  const match = href.match(regex);
-  if (!match) return null;
-
-  const [, waveId, serialNo, dropId] = match;
-  return { waveId, serialNo, dropId };
-}
+export function parseSeizeQuoteLink(href: string): SeizeQuoteLinkInfo | null {
+  try {
+    const baseUrl = getBaseUrl();
+    if (!baseUrl) return null;
+    let url: URL;
+    try {
+      url = new URL(href);
+    } catch {
+      url = new URL(href, baseUrl.origin);
+    }
+    if (url.origin !== baseUrl.origin) return null;
+    if (url.pathname !== "/waves") return null;
+    const waveId = url.searchParams.get("wave");
+    const serialNo = url.searchParams.get("serialNo");
+    if (!waveId || !serialNo) return null;
+    const dropId = url.searchParams.get("drop") || undefined;
+    return { waveId, serialNo, dropId };
+  } catch {
+    return null;
+  }
+}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24feb81 and f1dc85b.

📒 Files selected for processing (5)
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (5 hunks)
  • __tests__/helpers/SeizeLinkParser.test.ts (3 hunks)
  • components/drops/view/part/dropPartMarkdown/handlers/seize.tsx (2 hunks)
  • components/drops/view/part/dropPartMarkdown/linkHandlers.tsx (5 hunks)
  • helpers/SeizeLinkParser.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx}: Do not include any comments in the code
Use react-query for data fetching
Always add readonly before props

**/*.{ts,tsx}: Use TypeScript for source code and follow existing code style and naming conventions
Adhere to clean code standards as measured by SonarQube

Files:

  • __tests__/helpers/SeizeLinkParser.test.ts
  • components/drops/view/part/dropPartMarkdown/handlers/seize.tsx
  • components/drops/view/part/dropPartMarkdown/linkHandlers.tsx
  • helpers/SeizeLinkParser.ts
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
__tests__/**

📄 CodeRabbit inference engine (tests/AGENTS.md)

Place Jest test suites under the __tests__ directory mirroring source folders (e.g., components, contexts, hooks, utils)

Files:

  • __tests__/helpers/SeizeLinkParser.test.ts
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
__tests__/**/{fixtures,helpers}/**

📄 CodeRabbit inference engine (tests/AGENTS.md)

Put shared test fixtures and helpers in dedicated fixtures and helpers subfolders within tests

Files:

  • __tests__/helpers/SeizeLinkParser.test.ts
{**/__tests__/**,**/*.test.tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Place tests in tests directories or alongside components as ComponentName.test.tsx

Files:

  • __tests__/helpers/SeizeLinkParser.test.ts
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
{**/__tests__/**,**/*.test.{ts,tsx}}

📄 CodeRabbit inference engine (AGENTS.md)

Mock external dependencies and APIs in tests

Files:

  • __tests__/helpers/SeizeLinkParser.test.ts
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
**/*.tsx

📄 CodeRabbit inference engine (.cursorrules)

**/*.tsx: Use FontAwesome for icons
Use TailwindCSS for styling

Implement React components as functional components using hooks (no class components)

Files:

  • components/drops/view/part/dropPartMarkdown/handlers/seize.tsx
  • components/drops/view/part/dropPartMarkdown/linkHandlers.tsx
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
__tests__/components/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (tests/AGENTS.md)

Use @testing-library/react and @testing-library/user-event for React component tests

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
🧬 Code graph analysis (5)
__tests__/helpers/SeizeLinkParser.test.ts (1)
helpers/SeizeLinkParser.ts (1)
  • ensureStableSeizeLink (100-155)
components/drops/view/part/dropPartMarkdown/handlers/seize.tsx (1)
helpers/SeizeLinkParser.ts (1)
  • getSeizeBaseOrigin (29-32)
components/drops/view/part/dropPartMarkdown/linkHandlers.tsx (2)
helpers/SeizeLinkParser.ts (1)
  • ensureStableSeizeLink (100-155)
components/waves/LinkPreviewCard.tsx (1)
  • LinkPreviewCard (43-113)
helpers/SeizeLinkParser.ts (1)
next.config.mjs (2)
  • publicEnv (177-177)
  • publicEnv (235-235)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (2)
helpers/SeizeLinkParser.ts (1)
  • ensureStableSeizeLink (100-155)
components/drops/view/part/dropPartMarkdown/linkHandlers.tsx (1)
  • createLinkRenderer (56-195)
🪛 Biome (2.1.2)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx

[error] 14-14: expected , but instead found jest

Remove jest

(parse)


[error] 14-14: expected , but instead found .

Remove .

(parse)


[error] 14-14: Expected a property, a shorthand property, a getter, a setter, or a method but instead found '('.

Expected a property, a shorthand property, a getter, a setter, or a method here.

(parse)


[error] 14-14: Expected a function body but instead found '=>'.

Expected a function body here.

(parse)


[error] 15-15: expected , but instead found __esModule

Remove __esModule

(parse)


[error] 15-16: Expected a property, a shorthand property, a getter, a setter, or a method but instead found '-'.

Expected a property, a shorthand property, a getter, a setter, or a method here.

(parse)


[error] 16-16: Expected an expression but instead found 'default'.

Expected an expression here.

(parse)


[error] 16-16: expected , but instead found (

Remove (

(parse)


[error] 17-17: expected , but instead found default

Remove default

(parse)


[error] 17-17: expected , but instead found (

Remove (

(parse)


[error] 21-21: Expected an expression but instead found ')'.

Expected an expression here.

(parse)


[error] 10-10: This property is later overwritten by an object member with the same name.

Overwritten with this property.

If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property.

(lint/suspicious/noDuplicateObjectKeys)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (1)

224-237: Stable href behavior — tests read well

The normalization tests using ensureStableSeizeLink with an overridable current location correctly validate root rebasing and cross-path sharing. Nice.

Also applies to: 239-254

components/drops/view/part/dropPartMarkdown/linkHandlers.tsx (1)

70-85: Normalize before handling — solid integration

Using ensureStableSeizeLink consistently for validation, parsing, and previews tightens behavior and reduces edge cases. Good error-boundary fallbacks.

Also applies to: 91-99, 126-139, 149-149, 166-188

helpers/SeizeLinkParser.ts (3)

3-27: Cache BASE_ENDPOINT safely — LGTM

Cache refresh on env change is correct; null handling and parse guards are good.


51-71: Origin-validated query parsing — LGTM

Switching to URL with base-origin enforcement avoids false positives from relative/external links.


100-155: ensureStableSeizeLink is robust

Correctly rebases drop onto current same-origin path, preserving query and hash with safe fallbacks. Matches tests.

Signed-off-by: ragnep <ragneinfo@gmail.com>
Copy link
Copy Markdown

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

🧹 Nitpick comments (2)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (2)

218-231: Remove redundant cleanup call.

Line 230 calls setEnsureCurrentHref(undefined), but this is already handled in the afterEach hook at line 160.

Apply this diff:

     expect(screen.getByTestId("chat-buttons")).toHaveAttribute(
       "data-href",
       "https://6529.io/messages?wave=current-wave&drop=drop-123"
     );
-    setEnsureCurrentHref(undefined);
   });

233-248: Remove redundant cleanup call.

Line 247 calls setEnsureCurrentHref(undefined), but this is already handled in the afterEach hook at line 160.

Apply this diff:

     expect(screen.getByTestId("chat-buttons")).toHaveAttribute(
       "data-href",
       "https://6529.io/messages?wave=current-wave&drop=drop-456"
     );
-    setEnsureCurrentHref(undefined);
   });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1dc85b and 937388f.

📒 Files selected for processing (2)
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (6 hunks)
  • helpers/SeizeLinkParser.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx}: Do not include any comments in the code
Use react-query for data fetching
Always add readonly before props

**/*.{ts,tsx}: Use TypeScript for source code and follow existing code style and naming conventions
Adhere to clean code standards as measured by SonarQube

Files:

  • helpers/SeizeLinkParser.ts
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
**/*.tsx

📄 CodeRabbit inference engine (.cursorrules)

**/*.tsx: Use FontAwesome for icons
Use TailwindCSS for styling

Implement React components as functional components using hooks (no class components)

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
__tests__/**

📄 CodeRabbit inference engine (tests/AGENTS.md)

Place Jest test suites under the __tests__ directory mirroring source folders (e.g., components, contexts, hooks, utils)

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
__tests__/components/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (tests/AGENTS.md)

Use @testing-library/react and @testing-library/user-event for React component tests

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
{**/__tests__/**,**/*.test.tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Place tests in tests directories or alongside components as ComponentName.test.tsx

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
{**/__tests__/**,**/*.test.{ts,tsx}}

📄 CodeRabbit inference engine (AGENTS.md)

Mock external dependencies and APIs in tests

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
🧬 Code graph analysis (2)
helpers/SeizeLinkParser.ts (1)
next.config.mjs (2)
  • publicEnv (177-177)
  • publicEnv (235-235)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (2)
helpers/SeizeLinkParser.ts (1)
  • ensureStableSeizeLink (100-160)
components/drops/view/part/dropPartMarkdown/linkHandlers.tsx (1)
  • createLinkRenderer (56-195)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (10)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (5)

6-6: LGTM! Import supports the new mock functionality.

The import is correctly used in the SeizeLinkParser mock below to wrap the actual implementation with test-specific overrides.


18-20: LGTM! Mock correctly accepts and renders the src prop.


106-110: LGTM! Mock correctly reflects the updated DropItemChat signature.

The mock now accepts both dropId and href parameters and renders the nested chat-buttons element with the href attribute, which aligns with the component changes in this PR.


113-128: LGTM! Well-designed test mock for URL normalization.

The mock correctly wraps the actual implementation and provides a test-controlled override for currentHref, enabling tests to simulate different page contexts without polluting global state.


134-139: LGTM! Helper function provides clean test control.

helpers/SeizeLinkParser.ts (5)

3-4: LGTM! Cache variables support performance optimization.

The cache is properly invalidated when BASE_ENDPOINT changes (line 15 checks cachedBaseEndpoint === current), so this should work correctly even in test environments.


6-27: LGTM! Robust caching implementation with proper error handling.

The function correctly handles empty endpoints, invalid URLs, and cache invalidation when the endpoint changes.


29-32: LGTM! Clean helper for accessing the base origin.


58-70: LGTM! Improved origin validation using base URL.

The function now correctly validates links against the configured base origin rather than a hardcoded list, and properly handles relative URLs with the fallback at line 67.


100-160: LGTM! Comprehensive URL normalization with robust error handling.

The function correctly:

  • Validates same-origin URLs
  • Preserves the current page's path and existing query parameters
  • Updates only the drop parameter from the target URL
  • Maintains the current hash
  • Handles all edge cases with appropriate fallbacks

The early return at lines 122-124 when there's no drop parameter is appropriate, as this function specifically normalizes drop preview links.

Signed-off-by: ragnep <ragneinfo@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

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

🧹 Nitpick comments (3)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (3)

113-128: LGTM! Effective test infrastructure.

The mock wrapper pattern correctly injects currentHrefOverride for deterministic testing of location-dependent behavior.


Optional: Consider type-safe alternative to any assertion.

Line 120 uses any to attach the __setCurrentHref setter. While acceptable in tests, you could define a more specific type:

type MockedEnsureStableSeizeLink = typeof ensureStableSeizeLink & {
  __setCurrentHref: (href?: string) => void;
};

218-231: LGTM! Test correctly validates root drop link normalization.

The test properly verifies that drop links from the root path are normalized to use the current location's path and parameters.


Optional: Redundant cleanup call.

Line 230 calls setEnsureCurrentHref() but afterEach on Line 160 already performs this cleanup. The extra call is harmless but unnecessary.

     );
-    setEnsureCurrentHref();
   });

233-248: LGTM! Test correctly validates cross-path drop link normalization.

The test properly verifies that drop links from different paths are normalized to use the current location's context.


Optional: Redundant cleanup call.

Line 247 calls setEnsureCurrentHref() but afterEach on Line 160 already performs this cleanup.

     );
-    setEnsureCurrentHref();
   });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 937388f and e073343.

📒 Files selected for processing (2)
  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (6 hunks)
  • helpers/SeizeLinkParser.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx}: Do not include any comments in the code
Use react-query for data fetching
Always add readonly before props

**/*.{ts,tsx}: Use TypeScript for source code and follow existing code style and naming conventions
Adhere to clean code standards as measured by SonarQube

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
  • helpers/SeizeLinkParser.ts
**/*.tsx

📄 CodeRabbit inference engine (.cursorrules)

**/*.tsx: Use FontAwesome for icons
Use TailwindCSS for styling

Implement React components as functional components using hooks (no class components)

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
__tests__/**

📄 CodeRabbit inference engine (tests/AGENTS.md)

Place Jest test suites under the __tests__ directory mirroring source folders (e.g., components, contexts, hooks, utils)

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
__tests__/components/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (tests/AGENTS.md)

Use @testing-library/react and @testing-library/user-event for React component tests

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
{**/__tests__/**,**/*.test.tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Place tests in tests directories or alongside components as ComponentName.test.tsx

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
{**/__tests__/**,**/*.test.{ts,tsx}}

📄 CodeRabbit inference engine (AGENTS.md)

Mock external dependencies and APIs in tests

Files:

  • __tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx
🧬 Code graph analysis (2)
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (2)
helpers/SeizeLinkParser.ts (1)
  • ensureStableSeizeLink (100-160)
components/drops/view/part/dropPartMarkdown/linkHandlers.tsx (1)
  • createLinkRenderer (56-195)
helpers/SeizeLinkParser.ts (1)
next.config.mjs (2)
  • publicEnv (177-177)
  • publicEnv (235-235)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
helpers/SeizeLinkParser.ts (4)

3-27: LGTM! Clean caching implementation.

The memoization pattern correctly invalidates the cache when BASE_ENDPOINT changes and handles invalid URLs gracefully.


29-32: LGTM! Clean abstraction.

The function provides a clear public API for retrieving the base origin.


51-98: LGTM! Solid refactor.

Centralizing the base URL logic via getBaseUrl() and simplifying the origin validation improves maintainability. The fallback handling for relative URLs is appropriate.


100-160: URL transformation behavior is intentional—confirmed by test suite.

The function's URL restructuring is a design feature, not a bug. Tests explicitly validate this behavior ("rebases drop links from other paths onto current location"), confirming it extracts the drop parameter and applies it to the current page location. This is appropriate for the drop preview use case.

Optional: Simplify hash fallback.

Line 150: Remove unnecessary null-coalescing since URL.hash always returns a string:

-    const hash = currentUrl.hash ?? "";
+    const hash = currentUrl.hash;
__tests__/components/drops/view/part/dropPartMarkdown/linkHandlersRegistry.test.tsx (2)

104-111: LGTM! Mock properly updated.

The DropItemChat mock correctly accepts the new href parameter and exposes it via data-href attributes for test assertions.


134-139: LGTM! Clean test helper.

The helper provides a safer, more convenient API for controlling the mock's internal state.

@ragnep ragnep merged commit 7c85ac7 into main Oct 21, 2025
9 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Oct 21, 2025
@ragnep ragnep deleted the drop-preview-fix branch October 21, 2025 14:35
@coderabbitai coderabbitai Bot mentioned this pull request Nov 13, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Feb 20, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Mar 3, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants