Compare commits

..

5 Commits

Author SHA1 Message Date
dayuan.jiang
a0616c1ad8 fix: save session when diagram is modified via autosave
Add chartXML to dependency array of auto-save effect so that user
modifications in draw.io (captured via autosave) trigger session save.
2026-01-13 23:16:45 +09:00
dayuan.jiang
e271df43f8 fix: disable beforeunload warning from draw.io iframe
Set modified=false in urlParameters to prevent draw.io from triggering
the browser's 'Changes you made may not be saved' dialog on page refresh.
2026-01-13 23:15:21 +09:00
dayuan.jiang
38a247c55d refactor: use EventAutoSave type for type safety 2026-01-13 23:02:19 +09:00
dayuan.jiang
a0e3130ac2 fix: enable autosave to sync user modifications in draw.io
Previously, user modifications made directly in draw.io (moving nodes,
editing text, etc.) were not captured by React state until an explicit
export was triggered.

This adds the autosave feature from react-drawio:
- Enable autosave={true} on DrawIoEmbed component
- Add onAutoSave callback to update chartXML on every change
- Keep React state in sync with draw.io editor state
2026-01-13 22:54:02 +09:00
Dayuan Jiang
6bd26c8bbd Merge pull request #578 from DayuanJiang/fix/user-apikey-baseurl-isolation
fix: prevent user API keys from using server's baseURL
2026-01-13 22:26:12 +09:00
3 changed files with 21 additions and 3 deletions

View File

@@ -16,8 +16,13 @@ const drawioBaseUrl =
process.env.NEXT_PUBLIC_DRAWIO_BASE_URL || "https://embed.diagrams.net"
export default function Home() {
const { drawioRef, handleDiagramExport, onDrawioLoad, resetDrawioReady } =
useDiagram()
const {
drawioRef,
handleDiagramExport,
handleAutoSave,
onDrawioLoad,
resetDrawioReady,
} = useDiagram()
const router = useRouter()
const pathname = usePathname()
// Extract current language from pathname (e.g., "/zh/about" → "zh")
@@ -164,6 +169,8 @@ export default function Home() {
ref={drawioRef}
onExport={handleDiagramExport}
onLoad={handleDrawioLoad}
onAutoSave={handleAutoSave}
autosave={true}
baseUrl={drawioBaseUrl}
urlParameters={{
ui: drawioUi,
@@ -172,6 +179,7 @@ export default function Home() {
saveAndExit: false,
noSaveBtn: true,
noExitBtn: true,
modified: false,
dark: darkMode,
lang: currentLang,
}}

View File

@@ -639,6 +639,7 @@ export default function ChatPanel({
sessionIsAvailable,
currentSessionId,
buildSessionData,
chartXML,
])
// Update URL when a new session is created (first message sent)

View File

@@ -2,7 +2,7 @@
import type React from "react"
import { createContext, useContext, useEffect, useRef, useState } from "react"
import type { DrawIoEmbedRef } from "react-drawio"
import type { DrawIoEmbedRef, EventAutoSave } from "react-drawio"
import { toast } from "sonner"
import type { ExportFormat } from "@/components/save-dialog"
import { getApiEndpoint } from "@/lib/base-path"
@@ -23,6 +23,7 @@ interface DiagramContextType {
resolverRef: React.Ref<((value: string) => void) | null>
drawioRef: React.Ref<DrawIoEmbedRef | null>
handleDiagramExport: (data: any) => void
handleAutoSave: (data: EventAutoSave) => void
clearDiagram: () => void
saveDiagramToFile: (
filename: string,
@@ -226,6 +227,13 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
}
}
// Handle autosave events from draw.io - keeps chartXML in sync with user modifications
const handleAutoSave = (data: EventAutoSave) => {
if (data.xml) {
setChartXML(data.xml)
}
}
const clearDiagram = () => {
const emptyDiagram = `<mxfile><diagram name="Page-1" id="page-1"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>`
// Skip validation for trusted internal template (loadDiagram also sets chartXML)
@@ -350,6 +358,7 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
resolverRef,
drawioRef,
handleDiagramExport,
handleAutoSave,
clearDiagram,
saveDiagramToFile,
getThumbnailSvg,