Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
62f1dde
fix(security): bind stored login credentials to their server
qwqcode Nov 14, 2026
693a20f
fix(ui/conf): handle initialization retries and callback updates
qwqcode Nov 14, 2026
3c029cb
fix(ui/event): release listeners and pending work on destroy
qwqcode Nov 14, 2026
fb97b28
fix(ui/api): cancel stale requests and ignore outdated responses
qwqcode Nov 14, 2026
f3ca660
fix(ui/editor): preserve drafts and prevent duplicate submissions
qwqcode Nov 14, 2026
f8bf429
refactor(ui/marked): isolate parsers and preserve plugin extensions
qwqcode Nov 14, 2026
06514ee
fix(ci): build backend before starting end-to-end tests
qwqcode Nov 14, 2026
aac46c0
fix(ui/sidebar): hide admin controls in relocated comment lists
qwqcode Nov 14, 2026
598c122
fix(ui/sidebar): ignore outdated authentication checks
qwqcode Nov 14, 2026
06f88b1
fix(ui/emoticons): deduplicate merged groups
qwqcode Nov 14, 2026
34f819a
test(ui): exercise production builds in Chromium and WebKit
qwqcode Nov 14, 2026
874426c
fix(ui/pagination): validate page numbers and cancel stale input
qwqcode Nov 14, 2026
a83e4a6
fix(ui/plugins): share pending script loads across widgets
qwqcode Nov 14, 2026
1925a79
fix(ui/sidebar): discard stale management list responses
qwqcode Nov 14, 2026
16ad850
fix(ui/sidebar): clean up polling and comment route callbacks
qwqcode Nov 14, 2026
32be90d
fix(ui/error): simplify loading failure presentation
qwqcode Nov 14, 2026
ffe7d5a
fix(ui/version): show update notices only to administrators
qwqcode Nov 14, 2026
95fac8d
fix(ui/pagination): preserve comments after load-more failures
qwqcode Nov 14, 2026
1bfde3b
fix(ui/vote): prevent repeated votes while a request is pending
qwqcode Nov 14, 2026
d1d179a
fix(ui/error): show readable network failure messages
qwqcode Nov 14, 2026
d9b62cb
fix(ui/a11y): support keyboard use for comment actions
qwqcode Nov 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Install Chromium
run: pnpm exec playwright install --with-deps chromium
- name: Install browsers
run: pnpm exec playwright install --with-deps chromium webkit

- name: Build frontend
run: make build-frontend

- name: Build backend
run: make build-debug

- name: Run end-to-end tests
run: pnpm -F artalk test:e2e
Expand Down
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ The built binary file will be located in the `./bin` directory.

## Frontend Development (UI)

### Frontend State

Stored logins are scoped to the server URL. Legacy profile fields still load, but old tokens
without a server binding require a new login. Guest credentials keep their existing storage keys.
Use `ctx.getApi()` when starting a request so it uses the current server and user.

Initialize plugins after the final config is loaded. Retrying a failed initialization must not
register plugins or fire lifecycle events twice. Language settings are shared by the page.

Release listeners, timers, and pending work on `unmounted`. Cleanup must continue if another
plugin throws. A destroyed widget must not change the page or finish a login.

Keep list loading and cancellation in `ui/artalk/src/services/comments.ts`, using the existing
API. Check for stale results after `await`. Preserve v2 request fields and plugin events.

Drafts are stored per server, site, and page. The old draft is imported on first use.
Config updates must keep the current draft and reply or edit target. Navigation must clear the
old target without deleting its saved draft. Login retries must not submit twice.

Each widget owns its Markdown parser. Use `ctx.getMarked()` after `mounted` to add extensions.
Config updates keep the parser and its plugin extensions. Comments, quotes, and previews use
the same parser. Run `pnpm -F artalk test --run` to check these behaviors.

### Run Frontend

1. **Install Dependencies**:
Expand Down
14 changes: 14 additions & 0 deletions docs/docs/zh/develop/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ Artalk 是一个 monorepo 项目,这意味着所有源代码都在一个仓库

## 前端开发(UI)

### 前端状态

登录信息按服务端地址保存。旧昵称、邮箱和网址继续读取;旧 token 没有服务端归属,需要重新登录。匿名凭证沿用原存储键。发起请求时通过 `ctx.getApi()` 获取客户端,使用当前服务端和用户。

在最终配置加载后初始化插件。初始化失败后重试,不应重复注册插件或触发生命周期事件。语言设置由整个页面共用。

在 `unmounted` 中清理监听器、定时器和待完成任务。其他插件抛错时仍须继续清理;实例销毁后,不应再更新页面或完成登录。

列表加载和请求取消集中在 `ui/artalk/src/services/comments.ts`,复用现有 API。异步返回后检查结果是否仍然有效,并保留 v2 请求字段和插件事件。

草稿按服务端、站点和页面保存,旧草稿在首次使用时迁入。更新配置须保留草稿及回复、编辑目标;导航时清除旧目标,但不删除已保存的草稿。登录重试不应重复提交。

Markdown 解析器按实例管理。插件在 `mounted` 后通过 `ctx.getMarked()` 添加扩展;配置更新须保留解析器和插件扩展,评论、引用和预览共用同一解析器。运行 `pnpm -F artalk test --run` 验证这些行为。

### 运行前端

1. **安装依赖**:
Expand Down
10 changes: 4 additions & 6 deletions ui/artalk-sidebar/src/components/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ const emit = defineEmits<{

const curtPage = ref(1)
const offset = computed(() => pageSize.value * (curtPage.value - 1))
const maxPage = computed(() => Math.ceil(total.value / pageSize.value))
const maxPage = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
const prevDisabled = computed(() => curtPage.value - 1 < 1)
const nextDisabled = computed(() => curtPage.value + 1 > maxPage.value)

const inputValue = ref(String(curtPage.value))
let inputTimer: number | undefined
onUnmounted(() => window.clearTimeout(inputTimer))

function changePage(page: number) {
curtPage.value = page
Expand Down Expand Up @@ -62,6 +63,7 @@ function next() {
}

function reset() {
window.clearTimeout(inputTimer)
curtPage.value = 1
fillInput(1)
}
Expand All @@ -88,11 +90,7 @@ function triggerInput(now: boolean = false) {
return
}
let page = Number(value)
if (Number.isNaN(page)) {
revokeInput()
return
}
if (page < 1) {
if (!Number.isInteger(page) || page < 1) {
revokeInput()
return
}
Expand Down
52 changes: 52 additions & 0 deletions ui/artalk-sidebar/src/lib/comments-lifecycle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// @vitest-environment jsdom
import { expect, it, vi } from 'vitest'
import { createApp, ref } from 'vue'
import Comments from '../pages/comments.vue'

const widget = vi.hoisted(() => ({
getConf: () => ({ listFetchParamsModifier: undefined, scrollRelativeTo: undefined }),
reload: vi.fn(),
update: vi.fn(),
ctx: {
on: vi.fn(),
off: vi.fn(),
fetch: vi.fn(),
updateConf: vi.fn(),
editorResetState: vi.fn(),
inject: vi.fn(),
},
}))
vi.mock('../global', () => ({ artalk: widget }))
vi.mock('../stores/nav', () => ({
useNavStore: () => ({ curtTab: ref('all'), updateTabs: vi.fn(), enableSearch: vi.fn() }),
}))
vi.mock('../stores/user', () => ({
useUserStore: () => ({ site: ref('Test'), is_admin: true }),
}))

it('releases the comment listener, editor and callbacks when leaving the route', () => {
const list = document.createElement('div')
list.innerHTML = '<div class="atk-list-header"></div><div class="atk-list-footer"></div>'
widget.ctx.inject.mockReturnValue({ getEl: () => list })
for (let visit = 0; visit < 2; visit++) {
const container = document.createElement('div')
const app = createApp(Comments)
app.mount(container)
expect(container.contains(list)).toBe(true)
const listener = widget.ctx.on.mock.lastCall![1]
const setOpenURL = vi.fn()
listener({
getData: () => ({ page_url: 'https://example.com/post' }),
getID: () => 42,
getRender: () => ({ setOpenURL }),
})
expect(setOpenURL).toHaveBeenCalledWith('https://example.com/post#atk-comment-42')
app.unmount()
expect(widget.ctx.off).toHaveBeenLastCalledWith('comment-rendered', listener)
expect(widget.ctx.editorResetState).toHaveBeenCalledTimes(visit + 1)
expect(widget.update).toHaveBeenLastCalledWith({
listFetchParamsModifier: undefined,
scrollRelativeTo: undefined,
})
}
})
79 changes: 63 additions & 16 deletions ui/artalk-sidebar/src/lib/pages-filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createApp, nextTick, ref } from 'vue'
import Pages from '../pages/pages.vue'

const api = vi.hoisted(() => ({
getPages: vi.fn().mockResolvedValue({ data: { count: 0, pages: [] } }),
getPageFetchStatus: vi.fn().mockResolvedValue({ data: { is_progress: false } }),
}))
const nav = vi.hoisted(() => ({
updateTabs: vi.fn(),
enableSearch: vi.fn(),
setPageLoading: vi.fn(),
scrollPageToTop: vi.fn(),
isPageLoading: false,
}))
vi.mock('../global', () => ({
artalk: { ctx: { getApi: () => ({ pages: api }) } },
}))
vi.mock('../stores/nav', () => ({
useNavStore: () => ({
updateTabs: vi.fn(),
enableSearch: vi.fn(),
setPageLoading: vi.fn(),
scrollPageToTop: vi.fn(),
isPageLoading: false,
}),
useNavStore: () => nav,
}))
vi.mock('../stores/user', () => ({
useUserStore: () => ({ site: ref('Site A') }),
Expand All @@ -31,7 +32,15 @@ vi.mock('../components/Pagination.vue', () => ({
}))
vi.mock('../components/PageEditor.vue', () => ({ default: { render: () => null } }))

afterEach(() => vi.clearAllMocks())
beforeEach(() => {
api.getPages.mockResolvedValue({ data: { count: 0, pages: [] } })
api.getPageFetchStatus.mockResolvedValue({ data: { is_progress: false } })
})
afterEach(() => {
vi.clearAllTimers()
vi.useRealTimers()
vi.clearAllMocks()
})

describe('page list comment filter', () => {
it('requests only commented pages without an extra filter control', async () => {
Expand All @@ -41,17 +50,55 @@ describe('page list comment filter', () => {
try {
app.mount(container)
await nextTick()
expect(api.getPages).toHaveBeenLastCalledWith({
site_name: 'Site A',
offset: 0,
limit: 20,
search: '',
has_comments: true,
})
expect(api.getPages).toHaveBeenLastCalledWith(
{ site_name: 'Site A', offset: 0, limit: 20, search: '', has_comments: true },
{ signal: expect.any(AbortSignal) },
)
expect(container.querySelector('input[type="checkbox"]')).toBeNull()
} finally {
app.unmount()
container.remove()
}
})

it.each([false, true])(
'stops title polling on unmount (response pending: %s)',
async (pending) => {
vi.useFakeTimers()
let release!: (value: any) => void
api.getPageFetchStatus.mockReturnValueOnce(new Promise((resolve) => (release = resolve)))
const container = document.createElement('div')
const app = createApp(Pages)
app.mount(container)
if (!pending) {
release({ data: { is_progress: true, msg: 'Fetching titles' } })
await vi.advanceTimersByTimeAsync(0)
}
app.unmount()
if (pending) release({ data: { is_progress: true, msg: 'Fetching titles' } })
await vi.advanceTimersByTimeAsync(3000)
expect(api.getPageFetchStatus).toHaveBeenCalledTimes(1)
},
)

it('keeps the latest search result when an older request finishes last', async () => {
let release!: (value: any) => void
api.getPages.mockReturnValueOnce(new Promise((resolve) => (release = resolve)))
const container = document.createElement('div')
const app = createApp(Pages)
try {
app.mount(container)
api.getPages.mockResolvedValueOnce({
data: { count: 1, pages: [{ id: 2, title: 'Latest result', url: '/latest' }] },
})
nav.enableSearch.mock.calls[0][0]('latest')
await vi.waitFor(() => expect(container.textContent).toContain('Latest result'))
release({ data: { count: 1, pages: [{ id: 1, title: 'Stale result', url: '/stale' }] } })
await new Promise((resolve) => setTimeout(resolve, 0))
expect(container.textContent).toContain('Latest result')
expect(container.textContent).not.toContain('Stale result')
} finally {
app.unmount()
}
})
})
53 changes: 53 additions & 0 deletions ui/artalk-sidebar/src/lib/pagination.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// @vitest-environment jsdom
import { afterEach, expect, it, vi } from 'vitest'
import { createApp, nextTick } from 'vue'
import Pagination from '../components/Pagination.vue'

afterEach(() => vi.useRealTimers())

function mountPagination(total: number) {
const change = vi.fn()
const container = document.createElement('div')
const app = createApp(Pagination, { total, pageSize: 20, onChange: change })
const pagination = app.mount(container) as unknown as { reset: () => void }
const input = container.querySelector('input')!
return { change, app, input, pagination }
}

it('rejects fractional page numbers and keeps empty lists on page one', async () => {
const { change, app, input } = mountPagination(0)
try {
for (const value of ['1.5', 'Infinity', '-1', '', 'text']) {
input.value = value
input.dispatchEvent(new Event('input'))
input.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 13 }))
await nextTick()
expect(input.value).toBe('1')
expect(change).not.toHaveBeenCalled()
}
input.value = '99'
input.dispatchEvent(new Event('input'))
input.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 13 }))
await nextTick()
expect(input.value).toBe('1')
expect(change).toHaveBeenCalledExactlyOnceWith(0)
} finally {
app.unmount()
}
})

it('cancels delayed page input on reset and unmount', async () => {
vi.useFakeTimers()
const { change, app, input, pagination } = mountPagination(60)
input.value = '2'
input.dispatchEvent(new Event('input'))
pagination.reset()
await vi.advanceTimersByTimeAsync(1000)
expect(change).not.toHaveBeenCalled()
expect(input.value).toBe('1')
input.value = '3'
input.dispatchEvent(new Event('input'))
app.unmount()
await vi.advanceTimersByTimeAsync(1000)
expect(change).not.toHaveBeenCalled()
})
17 changes: 13 additions & 4 deletions ui/artalk-sidebar/src/pages/comments.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { storeToRefs } from 'pinia'
import type { EventPayloadMap } from 'artalk'
import { artalk } from '../global'
import { useNavStore } from '../stores/nav'
import { useUserStore } from '../stores/user'
Expand All @@ -12,6 +13,17 @@ const { curtTab } = storeToRefs(nav)
const { site: curtSite } = storeToRefs(user)

const search = ref('')
const { listFetchParamsModifier, scrollRelativeTo } = artalk!.getConf()
const onCommentRendered = (comment: EventPayloadMap['comment-rendered']) => {
const pageURL = comment.getData().page_url
comment.getRender().setOpenURL(`${pageURL}#atk-comment-${comment.getID()}`)
}

onBeforeUnmount(() => {
artalk!.ctx.off('comment-rendered', onCommentRendered)
artalk!.ctx.editorResetState()
artalk!.update({ listFetchParamsModifier, scrollRelativeTo })
})

onMounted(() => {
// 初始化导航条
Expand Down Expand Up @@ -46,10 +58,7 @@ onMounted(() => {
artalk!.ctx.reload()
})

artalk!.ctx.on('comment-rendered', (comment) => {
const pageURL = comment.getData().page_url
comment.getRender().setOpenURL(`${pageURL}#atk-comment-${comment.getID()}`)
})
artalk!.ctx.on('comment-rendered', onCommentRendered)

artalk!.ctx.updateConf({
listFetchParamsModifier: (params) => {
Expand Down
Loading
Loading