Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): prevent knowledge creation layout shifts when switching modes (#44806)

Stephen Zhou1dad48f0ef51
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index dbcff84d8ec..6d05a9e0bc8 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -6807,11 +6807,6 @@
"count": 4
}
},
- "web/features/new-rag/create/page.tsx": {
- "better-tailwindcss/enforce-logical-properties": {
- "count": 3
- }
- },
"web/features/new-rag/create/source-setup.tsx": {
"better-tailwindcss/enforce-logical-properties": {
"count": 1
diff --git a/web/features/new-rag/create/__tests__/upload-visibility.browser.spec.tsx b/web/features/new-rag/create/__tests__/upload-visibility.browser.spec.tsx
new file mode 100644
index 00000000000..899379413b6
--- /dev/null
+++ b/web/features/new-rag/create/__tests__/upload-visibility.browser.spec.tsx
@@ -0,0 +1,80 @@
+import type { NewKnowledgeStartMode } from '../../routes'
+import { RadioGroup } from '@langgenius/dify-ui/radio-group'
+import { useState } from 'react'
+import { page } from 'vite-plus/test/browser'
+import { render } from 'vitest-browser-react'
+import { StartMode } from '../components/dialog-parts'
+import { CreateUploadQueue } from '../upload-queue'
+
+vi.mock('../../upload/plan-notice', () => ({ DocumentUploadPlanNotice: () => null }))
+
+function ScrollableCreationModes() {
+ const [mode, setMode] = useState<NewKnowledgeStartMode>('empty')
+
+ return (
+ <section aria-label="Creation dialog" className="w-80 overflow-hidden">
+ <h1>Create knowledge</h1>
+ <section aria-label="Creation form" className="h-48 overflow-y-auto">
+ <div className="h-80" />
+ <RadioGroup value={mode} onValueChange={setMode} className="flex-col items-stretch">
+ <StartMode
+ value="empty"
+ selected={mode === 'empty'}
+ icon="i-ri-folder-6-line"
+ title="Start empty"
+ description="Add content later"
+ />
+ <StartMode
+ value="upload"
+ selected={mode === 'upload'}
+ icon="i-ri-file-text-line"
+ title="Upload files"
+ description="Add files from your computer"
+ >
+ <CreateUploadQueue
+ disabled={false}
+ fileSizeLimitMb={15}
+ supportBatchUpload
+ uploading={false}
+ uploads={[]}
+ onChange={vi.fn()}
+ />
+ </StartMode>
+ </RadioGroup>
+ </section>
+ <button type="button">Create</button>
+ </section>
+ )
+}
+
+it('reveals the entire upload drop zone on expansion without moving the panel or stealing focus', async () => {
+ // Real scrolling catches the expanded drop zone remaining clipped below the form viewport;
+ // DOM visibility assertions alone pass even when its lower edge cannot be seen.
+ await page.viewport(400, 600)
+ const screen = await render(<ScrollableCreationModes />)
+ const heading = screen.getByRole('heading', { name: 'Create knowledge' }).element()
+ const submit = screen.getByRole('button', { name: 'Create', exact: true }).element()
+ const headingTop = heading.getBoundingClientRect().top
+ const submitTop = submit.getBoundingClientRect().top
+ const form = screen.getByRole('region', { name: 'Creation form' }).element()
+ const upload = screen.getByRole('radio', { name: 'Upload files' })
+
+ for (let attempt = 0; attempt < 2; attempt++) {
+ await upload.click()
+ await expect.element(upload).toBeChecked()
+ await expect.element(upload).toHaveFocus()
+ const input = screen.getByLabelText('knowledgeSpace.uploadFiles').element() as HTMLInputElement
+ const dropzone = input.labels?.[0]
+ if (!dropzone) throw new Error('Upload input must have an associated drop zone label')
+ await expect
+ .poll(() => {
+ const box = dropzone.getBoundingClientRect()
+ const viewport = form.getBoundingClientRect()
+ return box.top >= viewport.top && box.bottom <= viewport.bottom
+ })
+ .toBe(true)
+ expect(heading.getBoundingClientRect().top).toBe(headingTop)
+ expect(submit.getBoundingClientRect().top).toBe(submitTop)
+ await screen.getByRole('radio', { name: 'Start empty' }).click()
+ }
+})
diff --git a/web/features/new-rag/create/page.tsx b/web/features/new-rag/create/page.tsx
index 7d85102c07c..1f842eaca85 100644
--- a/web/features/new-rag/create/page.tsx
+++ b/web/features/new-rag/create/page.tsx
@@ -408,26 +408,25 @@ function CreateKnowledgeSession() {
size="lg"
variant="ghost"
aria-label={tCommon(($) => $['operation.close'])}
- className="absolute top-3 right-3 z-10 bg-background-section-burn"
+ className="absolute inset-e-3 top-3 z-10 bg-background-section-burn"
onClick={requestClose}
disabled={submissionPending}
>
<span aria-hidden className="i-ri-close-line size-5" />
</IconButton>
- <div className="flex min-h-0 min-w-0 flex-col items-center border-divider-subtle xl:items-end xl:border-r">
- <div className="min-h-6 w-full max-w-180 flex-1 [@media(max-height:850px)]:h-6 [@media(max-height:850px)]:flex-none" />
+ <div className="flex min-h-0 min-w-0 flex-col items-center border-divider-subtle py-6 xl:items-end xl:border-e [@media(max-height:600px)]:py-3">
<Form
- className="flex max-h-full min-h-0 w-full max-w-180 flex-col"
+ className="flex min-h-0 w-full max-w-180 flex-1 flex-col"
onFormSubmit={() => void handleSubmit()}
>
- <header className="shrink-0 px-6 pt-2 pb-6 sm:px-10">
+ <header className="shrink-0 px-6 pt-2 pb-6 sm:px-10 [@media(max-height:600px)]:pb-3">
<DialogTitle id={dialogTitleId}>
{t(($) => $.createTitle, { ns: 'knowledgeCreate' })}
</DialogTitle>
</header>
- <div className="flex min-h-0 scrollbar-none flex-col gap-7 overflow-y-auto px-6 pb-7 sm:px-10">
+ <div className="flex min-h-0 flex-1 scrollbar-none flex-col gap-7 overflow-y-auto px-6 pb-7 sm:px-10">
<div className="flex flex-col gap-4">
<Field
name="name"
@@ -444,7 +443,7 @@ function CreateKnowledgeSession() {
>
<FieldLabel>
{t(($) => $.name)}
- <span aria-hidden className="ml-0.5 text-text-destructive">
+ <span aria-hidden className="ms-0.5 text-text-destructive">
*
</span>
</FieldLabel>
@@ -603,7 +602,7 @@ function CreateKnowledgeSession() {
</div>
</div>
- <div className="shrink-0 border-t border-divider-subtle px-6 pt-7 pb-12 sm:px-10">
+ <div className="shrink-0 border-t border-divider-subtle px-6 pt-7 pb-12 sm:px-10 [@media(max-height:600px)]:py-3">
{startMode === 'upload' && (
<ModelCostNotice
id={modelCostNoticeId}
@@ -633,7 +632,6 @@ function CreateKnowledgeSession() {
</div>
</div>
</Form>
- <div className="min-h-px w-full max-w-180 flex-1 [@media(max-height:850px)]:h-6 [@media(max-height:850px)]:flex-none" />
</div>
<aside className="hidden min-h-0 min-w-0 xl:block">
diff --git a/web/features/new-rag/create/upload-queue.tsx b/web/features/new-rag/create/upload-queue.tsx
index f30daa2c03e..e110de995ec 100644
--- a/web/features/new-rag/create/upload-queue.tsx
+++ b/web/features/new-rag/create/upload-queue.tsx
@@ -40,6 +40,10 @@ function mergeFiles(current: QueuedUpload[], files: File[], fileSizeLimitMb: num
]
}
+function revealDropzone(element: HTMLLabelElement | null) {
+ element?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
+}
+
export function CreateUploadQueue({
disabled,
fileSizeLimitMb,
@@ -82,9 +86,10 @@ export function CreateUploadQueue({
}}
/>
<label
+ ref={revealDropzone}
htmlFor={inputId}
className={cn(
- 'flex h-16 flex-col items-center justify-center gap-1 rounded-[10px] border border-dashed border-divider-regular bg-background-section px-4 text-center outline-hidden transition-colors motion-reduce:transition-none',
+ 'flex min-h-16 scroll-mb-4 flex-col items-center justify-center gap-1 rounded-[10px] border border-dashed border-divider-regular bg-background-section px-4 py-2 text-center outline-hidden transition-colors motion-reduce:transition-none',
'peer-focus-visible:ring-2 peer-focus-visible:ring-state-accent-solid',
disabled
? 'cursor-not-allowed opacity-60'