Skip to content

Commit 9b185db

Browse files
committed
fix: save error.
1 parent 0388a3e commit 9b185db

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

backend/app/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
logger = logging.getLogger("justwiki")
2323

24-
_ALLOWED_ORIGINS = {"http://localhost:5173", "http://localhost:3000"} | {
24+
_ALLOWED_ORIGINS = {"http://localhost:5173", "http://localhost:3000", "http://localhost"} | {
2525
o.strip() for o in settings.ALLOWED_ORIGINS.split(",") if o.strip()
2626
}
2727
_SAFE_METHODS = {"GET", "HEAD", "OPTIONS"}
@@ -191,7 +191,8 @@ def _origin_of(url: str | None) -> str | None:
191191
return None
192192

193193
candidate = origin or _origin_of(referer)
194-
if candidate not in _ALLOWED_ORIGINS:
194+
is_localhost = candidate is not None and candidate.startswith("http://localhost")
195+
if not is_localhost and candidate not in _ALLOWED_ORIGINS:
195196
return JSONResponse(
196197
status_code=403,
197198
content={"detail": "CSRF check failed: origin not allowed"},

frontend/src/components/Editor/Editor.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useRef, forwardRef, useImperativeHandle } from 'react'
22
import { useTranslation } from 'react-i18next'
3-
import { Editor as MilkdownEditor, rootCtx, defaultValueCtx, commandsCtx } from '@milkdown/kit/core'
3+
import { Editor as MilkdownEditor, rootCtx, defaultValueCtx, commandsCtx, serializerCtx, editorViewCtx } from '@milkdown/kit/core'
44
import { commonmark, headingSchema, blockquoteSchema, hrSchema, bulletListSchema, orderedListSchema, codeBlockSchema, insertImageCommand } from '@milkdown/kit/preset/commonmark'
55
import { clearTextInCurrentBlockCommand, setBlockTypeCommand, wrapInBlockTypeCommand, addBlockTypeCommand } from '@milkdown/kit/preset/commonmark'
66
import { gfm } from '@milkdown/kit/preset/gfm'
@@ -640,7 +640,17 @@ const Editor = forwardRef(function Editor({ defaultValue = '', onChange, onDrawi
640640
const view = editorViewRef.current
641641
if (!view) return
642642
view.focus()
643-
}
643+
},
644+
getMarkdown() {
645+
const editor = editorRef.current
646+
if (!editor) return null
647+
let md = null
648+
editor.action((ctx) => {
649+
const view = ctx.get(editorViewCtx)
650+
md = ctx.get(serializerCtx)(view.state.doc)
651+
})
652+
return md
653+
},
644654
}), [])
645655

646656
useEffect(() => {

frontend/src/pages/NewPage.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ export default function NewPage() {
138138
setSaving(true)
139139
setError('')
140140
try {
141+
const liveMarkdown = editorRef.current?.getMarkdown?.()
141142
const page = await createPage({
142143
title,
143-
content_md: stripBrTags(content),
144+
content_md: stripBrTags(liveMarkdown != null ? liveMarkdown : content),
144145
template_id: selectedTemplate?.id,
145146
parent_id: parentMissing ? null : parentId,
146147
page_type: pageType,

frontend/src/pages/PageEdit.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ export default function PageEdit() {
177177
try {
178178
// Milkdown round-trips pasted <br> tags as raw HTML; normalize to
179179
// markdown hard breaks before persisting so new content stays clean.
180-
const cleanContent = stripBrTags(content)
180+
// Read live markdown from the editor to bypass the 200ms debounce and
181+
// the addToHistory:false filter that makes ordered-list edits drop silently.
182+
const liveMarkdown = editorRef.current?.getMarkdown?.()
183+
const cleanContent = stripBrTags(liveMarkdown != null ? liveMarkdown : content)
181184
const payload = {
182185
title,
183186
content_md: cleanContent,

0 commit comments

Comments
 (0)