Skip to content

Conversation

@AdityaHegde
Copy link
Collaborator

A link in embed can cause issues on cmd/ctrl+click. The link opened will be the iframe url which will not open. So we need to convert it to a button to avoid such issues.

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@ericpgreen2
Copy link
Contributor

Thanks for the fix! The core issue makes sense - cmd/ctrl+click on links in embedded iframes doesn't work as expected.

The implementation works, but I wanted to share some thoughts on the approach and potential alternatives.

Current approach concerns:

The button + data-url-params + event delegation pattern feels a bit hacky:

  • Raw HTML string templating with data attributes
  • Event delegation on a parent div with target inspection
  • Two rendering paths (button vs link) in the markdown renderer
  • svelte-ignore comments for accessibility

Short-term alternative - Svelte Action:

Instead of branching in the renderer, we could keep <a> tags everywhere and use a Svelte action to intercept clicks in embedded contexts:

// citation-link-action.ts
export function enhanceCitationLinks(node: HTMLElement) {
  const isEmbedded = EmbedStore.isEmbedded();
  
  function handleClick(e: MouseEvent) {
    const link = (e.target as HTMLElement)?.closest("a[data-citation]");
    if (!link || !isEmbedded) return;
    
    e.preventDefault();
    const href = link.getAttribute("href");
    if (href) goto(href);
  }

  node.addEventListener("click", handleClick);
  return {
    destroy() { node.removeEventListener("click", handleClick); },
  };
}

This keeps semantic <a> tags, preserves URL preview on hover in the app, and centralizes the embed-specific behavior. Less invasive than the current approach while solving the same problem.

Medium-term idea - Structured Citations:

The deeper issue is that citations are embedded in markdown strings, forcing us to parse/rewrite HTML. One option would be to have the backend return citations as structured data separate from the markdown content, letting the frontend render them as proper Svelte components.

I've drafted a proposal for this approach here: https://www.notion.so/rilldata/Citation-URLs-tech-clean-up-2c5ba33c8f578030813df6ab43bbb64d

Would love feedback on whether this direction makes sense or if there are concerns I'm not seeing.


If we need to ship quickly, the current PR works. Happy to discuss either alternative further.

Developed in collaboration with Claude Code

Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to the approach in the PR as-is, but it doesn't feel like the most maintainable, ideal design. Thoughts on the two ideas (one a quicker idea that might help code co-location; one a larger-scale refactor) mentioned above?

@AdityaHegde AdityaHegde force-pushed the feat/move-citation-urls-to-buttons branch from 051db96 to aab26c8 Compare December 11, 2025 12:10
@AdityaHegde
Copy link
Collaborator Author

AdityaHegde commented Dec 11, 2025

Even in non-embed it would do a full page refresh. So I opted to always use goto. There is a safeguard for cmd/ctrl+click in embedded context.
There is another option to not have rewrite at all and only rely on the click handler. But we will lose the option to remove the link if it is invalid.

As for the long term fix,

  1. We dont really do additional parsing. We piggy back on marked library which already does a markdown => html conversion. It just has a hook to transform the final html.
  2. We are still parsing and rewriting the response, [citation:N] => segments.
  3. Doing partial conversion from markdown and rendering them in segments doesnt feel right to me. If we do this, we should rely on marked library to create svelte components for us.

@AdityaHegde AdityaHegde force-pushed the feat/move-citation-urls-to-buttons branch from aab26c8 to 80517df Compare December 11, 2025 12:13
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve the PR, and we can pick up the long-term architecture another time. For this PR though– thoughts on the Svelte Action approach, or otherwise encapsulating the complexity & moving it out of the TextMessage.svelte (AssistantMessage.svelte, on main) component? Perhaps we should have one file /chat/core/messages/text/citation-urls.ts that holds all the logic.

@ericpgreen2
Copy link
Contributor

Here's where we can continue the discussion of the longer-term refactor: #8502

@AdityaHegde AdityaHegde merged commit 704a143 into main Dec 15, 2025
10 checks passed
@AdityaHegde AdityaHegde deleted the feat/move-citation-urls-to-buttons branch December 15, 2025 06:23
AdityaHegde added a commit that referenced this pull request Dec 18, 2025
* fix: move citation urls to buttons in embed

* Remove checks for embedded context

* Move action out of svelte
k-anshul pushed a commit that referenced this pull request Dec 18, 2025
* fix: move citation urls to buttons in embed

* Remove checks for embedded context

* Move action out of svelte
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.

3 participants