fix: a note or channel link in a chat message opens beside the chat instead of replacing it (#34302)

This commit is contained in:
G30 authored and GitHub committed 2026-11-13 18:07:54 +09:00
1 parent b488131894
commit cfe0ca0f6b
3 files changed
+15 -3

No files matched your search

@@ -3,10 +3,12 @@
import { toast } from 'svelte-sonner';
import type { Token, Tokens } from 'marked';
import type { AppLayoutContext } from '$lib/types';
import { getContext } from 'svelte';
import { goto } from '$app/navigation';
const i18n = getContext('i18n');
const appLayout = getContext<AppLayoutContext | undefined>('appLayout');
const terminalDocument = getContext<
| {
localPath: (ref: string) => string | null;
@@ -86,7 +88,9 @@
url.pathname.startsWith('/channels/'))
) {
e.preventDefault();
goto(url.pathname + url.search + url.hash);
if (appLayout?.openPageTab && !url.pathname.startsWith('/c/'))
appLayout.openPageTab({ href: url.pathname + url.search + url.hash, label: '' });
else goto(url.pathname + url.search + url.hash);
}
} catch {
// Invalid URL, let browser handle it
@@ -22,10 +22,12 @@
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import type { AppLayoutContext } from '$lib/types';
import { channels, models } from '$lib/stores';
import UserStatusLinkPreview from '$lib/components/channel/Messages/Message/UserStatusLinkPreview.svelte';
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
const appLayout = getContext<AppLayoutContext | undefined>('appLayout');
export let token: Tokens.Generic;
@@ -158,7 +160,9 @@
if (idType === 'C') {
// Open channel
if ($channels.find((c) => c.id === id)) {
await goto(`/channels/${id}`);
if (appLayout?.openPageTab)
appLayout.openPageTab({ href: `/channels/${id}`, label: '' });
else await goto(`/channels/${id}`);
}
} else if (idType === 'T') {
// Open thread
@@ -1,11 +1,13 @@
<script lang="ts">
import { onMount, getContext } from 'svelte';
import { goto } from '$app/navigation';
import type { AppLayoutContext } from '$lib/types';
import { getNoteById } from '$lib/apis/notes';
import { getUserInfoById } from '$lib/apis/users';
import { capitalizeFirstLetter } from '$lib/utils';
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
const appLayout = getContext<AppLayoutContext | undefined>('appLayout');
export let noteId: string;
export let href: string;
@@ -50,7 +52,9 @@
on:click|preventDefault|stopPropagation={() => {
try {
const url = new URL(href, window.location.origin);
goto(url.pathname + url.search + url.hash);
if (appLayout?.openPageTab)
appLayout.openPageTab({ href: url.pathname + url.search + url.hash, label: '' });
else goto(url.pathname + url.search + url.hash);
} catch {
// fallback
}