fix local markdown attachment regressions

This commit is contained in:
lix-2026
2026-05-29 11:13:05 +08:00
parent 1109e3c0d8
commit cbe789e034
63 changed files with 3249 additions and 1502 deletions
@@ -250,12 +250,19 @@ fn escape_script_json(value: &str) -> String {
value.replace("</script", "<\\/script")
}
fn render_mindmap_standalone_bootstrap_script() -> &'static str {
fn render_mindmap_standalone_bootstrap_script() -> String {
r#"<script type="module">
(() => {
const DEV_HOT_BUSTER = "__MNOTE_DEV_HOT_BUSTER__";
const BOOTSTRAP_ID = '__MNOTE_MINDMAP_EDITOR_BOOTSTRAP__';
const MOUNT_ID = 'mnote-mindmap-island';
const withDevHot = (path) => {
const url = new URL(path, window.location.origin);
if (DEV_HOT_BUSTER) url.searchParams.set('devHot', DEV_HOT_BUSTER);
return url.toString();
};
const parseJsonScript = (id) => {
const node = document.getElementById(id);
if (!node) return null;
@@ -272,12 +279,12 @@ fn render_mindmap_standalone_bootstrap_script() -> &'static str {
return window.__mnoteLeptosTiptapRuntimePromise;
}
window.__mnoteLeptosTiptapRuntimePromise = (async () => {
const manifestResponse = await fetch('/api/leptos-tiptap-runtime/manifest.json');
const manifestResponse = await fetch(withDevHot('/api/leptos-tiptap-runtime/manifest.json'));
if (!manifestResponse.ok) throw new Error(`manifest_failed_${manifestResponse.status}`);
const manifest = await manifestResponse.json();
if (!manifest.entryAssetPath) throw new Error('island manifest 缺少 entryAssetPath');
const entryUrl = `/api/leptos-tiptap-runtime/${manifest.entryAssetPath}`;
const wasmUrl = manifest.wasmAssetPath ? `/api/leptos-tiptap-runtime/${manifest.wasmAssetPath}` : undefined;
const entryUrl = withDevHot(`/api/leptos-tiptap-runtime/${manifest.entryAssetPath}`);
const wasmUrl = manifest.wasmAssetPath ? withDevHot(`/api/leptos-tiptap-runtime/${manifest.wasmAssetPath}`) : undefined;
const runtime = await import(entryUrl);
if (typeof runtime.default !== 'function' || typeof runtime.mount !== 'function' || typeof runtime.unmount !== 'function') {
throw new Error('island runtime 导出不完整');
@@ -322,12 +329,16 @@ fn render_mindmap_standalone_bootstrap_script() -> &'static str {
}, { once: true });
})();
</script>"#
.replace(
"__MNOTE_DEV_HOT_BUSTER__",
crate::routes::dev_hot::dev_hot_cache_buster().unwrap_or(""),
)
}
#[cfg(test)]
mod tests {
use crate::app::{AppConfig, AppState, build_app};
use axum::body::{Body, to_bytes};
use crate::app::{build_app, AppConfig, AppState};
use axum::body::{to_bytes, Body};
use axum::http::{Request, StatusCode};
use tower::util::ServiceExt;
@@ -493,6 +504,25 @@ mod tests {
assert!(!html.contains("next-app-router"));
}
#[test]
fn mindmap_standalone_bootstrap_propagates_dev_hot_to_island_runtime() {
let _guard = crate::test_support::hermes_env_lock()
.lock()
.expect("env lock");
std::env::set_var("MNOTE_WEB_DEV_HOT_RELOAD", "1");
let script = super::render_mindmap_standalone_bootstrap_script();
std::env::remove_var("MNOTE_WEB_DEV_HOT_RELOAD");
assert!(script.contains("const DEV_HOT_BUSTER = \""));
assert!(script.contains("fetch(withDevHot('/api/leptos-tiptap-runtime/manifest.json'))"));
assert!(
script.contains("withDevHot(`/api/leptos-tiptap-runtime/${manifest.entryAssetPath}`)")
);
assert!(
script.contains("withDevHot(`/api/leptos-tiptap-runtime/${manifest.wasmAssetPath}`)")
);
}
#[tokio::test]
async fn mindmap_api_returns_same_adapter_contract_for_standalone_and_block() {
let response = app_with_mindmap_fixture()