Compare commits
11 Commits
369b4838a3
...
62fe87961f
| Author | SHA1 | Date | |
|---|---|---|---|
| 62fe87961f | |||
| 431e6e1db4 | |||
| 48a328f553 | |||
| 962bef2276 | |||
| 45811df96e | |||
| 408b29dd9d | |||
| 8855cdd49d | |||
| 656e35c79f | |||
| 0b53e968c1 | |||
| fbd706b198 | |||
| d1b5b8ee4e |
8
Makefile
8
Makefile
@ -1,4 +1,4 @@
|
|||||||
.PHONY: dev build build-linux css css-watch clean build-editor build-editor-incremental build-lightbox build-lightbox-incremental build-core build-core-incremental highlight-css test doc doc-open start
|
.PHONY: dev build build-linux css css-watch clean build-editor build-editor-incremental build-lightbox build-lightbox-incremental build-core build-core-incremental highlight-css test doc doc-open start clippy fix
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@$(MAKE) build-editor
|
@$(MAKE) build-editor
|
||||||
@ -75,6 +75,12 @@ test:
|
|||||||
@cd libs/lightbox && pnpm test
|
@cd libs/lightbox && pnpm test
|
||||||
@cd libs/yggdrasil-core && pnpm test
|
@cd libs/yggdrasil-core && pnpm test
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
@cargo clippy --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
|
fix:
|
||||||
|
@cargo fix --allow-dirty
|
||||||
|
|
||||||
# 只编译当前 crate 的文档(--no-deps 跳过依赖,--document-private-items
|
# 只编译当前 crate 的文档(--no-deps 跳过依赖,--document-private-items
|
||||||
# 让纯 binary crate 的内部模块/私有项也进文档,否则页面基本是空的)。
|
# 让纯 binary crate 的内部模块/私有项也进文档,否则页面基本是空的)。
|
||||||
# RUSTDOCFLAGS 把 rustdoc 的 --default-theme=ayu 透传过去——cargo doc 本身
|
# RUSTDOCFLAGS 把 rustdoc 的 --default-theme=ayu 透传过去——cargo doc 本身
|
||||||
|
|||||||
@ -707,3 +707,4 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ========== Blur-up 渐进图片加载(已移入 @layer components) ========== */
|
/* ========== Blur-up 渐进图片加载(已移入 @layer components) ========== */
|
||||||
|
@source "./src/**/*.{rs,html}";
|
||||||
|
|||||||
BIN
public/images/xiantiaoxiaogou_03.webp
Normal file
BIN
public/images/xiantiaoxiaogou_03.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 452 KiB |
@ -147,13 +147,20 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>, parent_indent: Option<i
|
|||||||
class: "block text-sm font-medium text-paper-secondary mb-1",
|
class: "block text-sm font-medium text-paper-secondary mb-1",
|
||||||
"内容 *"
|
"内容 *"
|
||||||
}
|
}
|
||||||
|
div { class: "relative bg-paper-entry rounded-lg",
|
||||||
textarea {
|
textarea {
|
||||||
id: "comment-content-{id_suffix}",
|
id: "comment-content-{id_suffix}",
|
||||||
class: "{INPUT_CLASS} min-h-[100px] resize-y",
|
class: "{INPUT_CLASS} !bg-transparent relative z-10 peer block min-h-[100px] resize-y",
|
||||||
value: "{content_md}",
|
value: "{content_md}",
|
||||||
disabled: submitting(),
|
disabled: submitting(),
|
||||||
oninput: move |e| content_md.set(e.value()),
|
oninput: move |e| content_md.set(e.value()),
|
||||||
}
|
}
|
||||||
|
img {
|
||||||
|
src: "/images/xiantiaoxiaogou_03.webp",
|
||||||
|
alt: "",
|
||||||
|
class: "absolute bottom-1.5 right-1.5 w-24 pointer-events-none opacity-60 peer-focus:opacity-10 transition-opacity duration-300 z-0",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p { class: "text-xs text-paper-tertiary", "支持 Markdown 语法" }
|
p { class: "text-xs text-paper-tertiary", "支持 Markdown 语法" }
|
||||||
|
|||||||
@ -77,7 +77,7 @@ pub fn CommentItem(comment: PublicComment, post_id: i32) -> Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div {
|
div {
|
||||||
class: "prose prose-sm dark:prose-invert max-w-none text-paper-secondary",
|
class: "prose prose-sm dark:prose-invert max-w-none text-paper-secondary md-content",
|
||||||
dangerous_inner_html: comment.content_html.as_deref().unwrap_or(""),
|
dangerous_inner_html: comment.content_html.as_deref().unwrap_or(""),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -207,6 +207,7 @@ pub fn FilterTabs(
|
|||||||
let mut indicator_style = use_signal(|| "left: 0px; width: 0px; opacity: 0;".to_string());
|
let mut indicator_style = use_signal(|| "left: 0px; width: 0px; opacity: 0;".to_string());
|
||||||
let id_prefix = use_hook(|| TAB_GROUP_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst));
|
let id_prefix = use_hook(|| TAB_GROUP_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst));
|
||||||
|
|
||||||
|
#[cfg_attr(not(target_arch = "wasm32"), allow(unused_variables))]
|
||||||
let update_indicator = move |active: String| {
|
let update_indicator = move |active: String| {
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
@ -254,11 +255,7 @@ pub fn FilterTabs(
|
|||||||
button {
|
button {
|
||||||
id: "tab-{id_prefix}-{value}",
|
id: "tab-{id_prefix}-{value}",
|
||||||
key: "{value}",
|
key: "{value}",
|
||||||
class: if active_value == *value {
|
class: if active_value == *value { "cursor-pointer px-4 py-2 text-sm font-medium text-paper-primary transition-colors" } else { "cursor-pointer px-4 py-2 text-sm font-medium text-paper-secondary hover:text-paper-primary transition-colors" },
|
||||||
"cursor-pointer px-4 py-2 text-sm font-medium text-paper-primary transition-colors"
|
|
||||||
} else {
|
|
||||||
"cursor-pointer px-4 py-2 text-sm font-medium text-paper-secondary hover:text-paper-primary transition-colors"
|
|
||||||
},
|
|
||||||
onclick: {
|
onclick: {
|
||||||
let v = value.to_string();
|
let v = value.to_string();
|
||||||
move |_| {
|
move |_| {
|
||||||
|
|||||||
@ -336,25 +336,25 @@ mod tests {
|
|||||||
fn relative_label_hours() {
|
fn relative_label_hours() {
|
||||||
let (label, _) = relative_label_from_millis(60 * 60_000, ISO);
|
let (label, _) = relative_label_from_millis(60 * 60_000, ISO);
|
||||||
assert_eq!(label, "1 小时前");
|
assert_eq!(label, "1 小时前");
|
||||||
let (label, _) = relative_label_from_millis(3 * 3600_000, ISO);
|
let (label, _) = relative_label_from_millis(3 * 3_600_000, ISO);
|
||||||
assert_eq!(label, "3 小时前");
|
assert_eq!(label, "3 小时前");
|
||||||
let (label, _) = relative_label_from_millis(23 * 3600_000, ISO);
|
let (label, _) = relative_label_from_millis(23 * 3_600_000, ISO);
|
||||||
assert_eq!(label, "23 小时前");
|
assert_eq!(label, "23 小时前");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn relative_label_days() {
|
fn relative_label_days() {
|
||||||
let (label, _) = relative_label_from_millis(24 * 3600_000, ISO);
|
let (label, _) = relative_label_from_millis(24 * 3_600_000, ISO);
|
||||||
assert_eq!(label, "1 天前");
|
assert_eq!(label, "1 天前");
|
||||||
let (label, _) = relative_label_from_millis(7 * 24 * 3600_000, ISO);
|
let (label, _) = relative_label_from_millis(7 * 24 * 3_600_000, ISO);
|
||||||
assert_eq!(label, "7 天前");
|
assert_eq!(label, "7 天前");
|
||||||
let (label, _) = relative_label_from_millis(29 * 24 * 3600_000, ISO);
|
let (label, _) = relative_label_from_millis(29 * 24 * 3_600_000, ISO);
|
||||||
assert_eq!(label, "29 天前");
|
assert_eq!(label, "29 天前");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn relative_label_falls_back_to_date_over_30_days() {
|
fn relative_label_falls_back_to_date_over_30_days() {
|
||||||
let (label, absolute) = relative_label_from_millis(60 * 24 * 3600_000, ISO);
|
let (label, absolute) = relative_label_from_millis(60 * 24 * 3_600_000, ISO);
|
||||||
assert_eq!(label, "2026-06-22");
|
assert_eq!(label, "2026-06-22");
|
||||||
assert_eq!(absolute, "2026-06-22");
|
assert_eq!(absolute, "2026-06-22");
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/main.rs
20
src/main.rs
@ -325,16 +325,20 @@ fn main() {
|
|||||||
// 配置增量渲染缓存,默认缓存 3600 秒,可通过 SSR_CACHE_SECS 覆盖。
|
// 配置增量渲染缓存,默认缓存 3600 秒,可通过 SSR_CACHE_SECS 覆盖。
|
||||||
// 注意:src/ssr_cache.rs 中的世代号是未来就绪基础设施,当前并不会使
|
// 注意:src/ssr_cache.rs 中的世代号是未来就绪基础设施,当前并不会使
|
||||||
// Dioxus 0.7 的 SSR 缓存实际失效(Dioxus 未暴露相应 API)。在 API 可用
|
// Dioxus 0.7 的 SSR 缓存实际失效(Dioxus 未暴露相应 API)。在 API 可用
|
||||||
// 之前,SSR_CACHE_SECS 仍是唯一有效的兜底 TTL。
|
// 之前,SSR_CACHE_SECS 仍是唯一有效的兜底 TTL——它就是内容写入后
|
||||||
let config = ServeConfig::builder().incremental(
|
// SSR 页面可见滞后的上界。
|
||||||
dioxus::server::IncrementalRendererConfig::default().invalidate_after(
|
let ssr_cache_secs = std::env::var("SSR_CACHE_SECS")
|
||||||
std::time::Duration::from_secs(
|
|
||||||
std::env::var("SSR_CACHE_SECS")
|
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|s| s.parse().ok())
|
.and_then(|s| s.parse().ok())
|
||||||
.unwrap_or(3600),
|
.unwrap_or(3600);
|
||||||
),
|
tracing::info!(
|
||||||
),
|
ssr_cache_secs,
|
||||||
|
"增量渲染缓存生效(写入后内容可见滞后的上界);\
|
||||||
|
调小可缩短滞后,代价是 SSR 重渲染更频繁"
|
||||||
|
);
|
||||||
|
let config = ServeConfig::builder().incremental(
|
||||||
|
dioxus::server::IncrementalRendererConfig::default()
|
||||||
|
.invalidate_after(std::time::Duration::from_secs(ssr_cache_secs)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// SSR 世代号中间件:把当前全局世代号注入请求扩展,并对 GET 请求的
|
// SSR 世代号中间件:把当前全局世代号注入请求扩展,并对 GET 请求的
|
||||||
|
|||||||
@ -17,26 +17,7 @@ pub fn About() -> Element {
|
|||||||
h1 { class: "text-4xl font-bold text-paper-primary tracking-tight", "关于" }
|
h1 { class: "text-4xl font-bold text-paper-primary tracking-tight", "关于" }
|
||||||
}
|
}
|
||||||
article { class: "prose dark:prose-invert max-w-none text-paper-content leading-relaxed",
|
article { class: "prose dark:prose-invert max-w-none text-paper-content leading-relaxed",
|
||||||
p { "Yggdrasil 是一个以文字为主的简约博客系统。" }
|
p { "世界……遗忘我……" }
|
||||||
p {
|
|
||||||
"它使用 Rust + Dioxus 构建,采用 PostgreSQL 作为数据库,支持 Markdown 写作、标签管理和暗色模式。"
|
|
||||||
}
|
|
||||||
h2 { class: "text-xl font-bold text-paper-primary mt-8 mb-4", "技术栈" }
|
|
||||||
ul { class: "list-disc pl-5 space-y-1",
|
|
||||||
li { "Rust + Dioxus 0.7 (全栈 Web 框架)" }
|
|
||||||
li { "PostgreSQL + tokio-postgres (数据库)" }
|
|
||||||
li { "Tailwind CSS (样式)" }
|
|
||||||
li { "Tiptap Editor (富文本编辑器)" }
|
|
||||||
li { "pulldown-cmark (Markdown 渲染)" }
|
|
||||||
}
|
|
||||||
h2 { class: "text-xl font-bold text-paper-primary mt-8 mb-4", "特性" }
|
|
||||||
ul { class: "list-disc pl-5 space-y-1",
|
|
||||||
li { "Markdown 写作与实时预览" }
|
|
||||||
li { "文章标签与归档" }
|
|
||||||
li { "暗色/亮色主题切换" }
|
|
||||||
li { "响应式设计" }
|
|
||||||
li { "文章搜索" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,7 +99,7 @@ pub fn PostsPage(page: i32) -> Element {
|
|||||||
action: EmptyStateAction {
|
action: EmptyStateAction {
|
||||||
label: "写文章".to_string(),
|
label: "写文章".to_string(),
|
||||||
to: Route::Write {},
|
to: Route::Write {},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
div { class: "{ADMIN_TABLE_CLASS}",
|
div { class: "{ADMIN_TABLE_CLASS}",
|
||||||
|
|||||||
@ -106,7 +106,6 @@ pub fn TrashPage(page: i32) -> Element {
|
|||||||
// 自动清理配置卡片(抽取为子组件 AutoPurgeSettings,见文件末尾)。
|
// 自动清理配置卡片(抽取为子组件 AutoPurgeSettings,见文件末尾)。
|
||||||
AutoPurgeSettings { settings }
|
AutoPurgeSettings { settings }
|
||||||
|
|
||||||
|
|
||||||
// 批量操作栏(选中时显示)
|
// 批量操作栏(选中时显示)
|
||||||
if !selected_ids().is_empty() {
|
if !selected_ids().is_empty() {
|
||||||
div { class: "flex items-center gap-3 p-3 bg-paper-theme rounded-lg",
|
div { class: "flex items-center gap-3 p-3 bg-paper-theme rounded-lg",
|
||||||
@ -214,7 +213,7 @@ pub fn TrashPage(page: i32) -> Element {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
th { class: "px-4 py-3 font-medium", "标题" }
|
th { class: "px-4 py-3 font-medium", "标题" }
|
||||||
th { class: "px-4 py-3 font-medium", "原状态" } // 底部:清空回收站 + 分页
|
th { class: "px-4 py-3 font-medium", "原状态" }
|
||||||
th { class: "px-4 py-3 font-medium w-28", "删除时间" }
|
th { class: "px-4 py-3 font-medium w-28", "删除时间" }
|
||||||
th { class: "px-4 py-3 font-medium w-24 text-center", "剩余" }
|
th { class: "px-4 py-3 font-medium w-24 text-center", "剩余" }
|
||||||
th { class: "px-4 py-3 font-medium w-32 text-right", "操作" }
|
th { class: "px-4 py-3 font-medium w-32 text-right", "操作" }
|
||||||
@ -425,11 +424,7 @@ fn AutoPurgeSettings(settings: Signal<TrashSettings>) -> Element {
|
|||||||
// 设置面板(可折叠带平滑动画)
|
// 设置面板(可折叠带平滑动画)
|
||||||
div {
|
div {
|
||||||
class: "grid transition-all duration-300 ease-in-out",
|
class: "grid transition-all duration-300 ease-in-out",
|
||||||
style: if settings_panel_open() {
|
style: if settings_panel_open() { "grid-template-rows: 1fr; opacity: 1; pointer-events: auto;" } else { "grid-template-rows: 0fr; opacity: 0; pointer-events: none;" },
|
||||||
"grid-template-rows: 1fr; opacity: 1; pointer-events: auto;"
|
|
||||||
} else {
|
|
||||||
"grid-template-rows: 0fr; opacity: 0; pointer-events: none;"
|
|
||||||
},
|
|
||||||
div { class: "overflow-hidden min-h-0",
|
div { class: "overflow-hidden min-h-0",
|
||||||
div { class: "border-t border-paper-border p-5 space-y-6",
|
div { class: "border-t border-paper-border p-5 space-y-6",
|
||||||
// 开关行:启用自动清理
|
// 开关行:启用自动清理
|
||||||
@ -665,8 +660,6 @@ fn TrashRow(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_auto_purge_settings_has_transition_class() {
|
fn test_auto_purge_settings_has_transition_class() {
|
||||||
let full_code = include_str!("trash.rs");
|
let full_code = include_str!("trash.rs");
|
||||||
|
|||||||
@ -458,8 +458,13 @@ fn write_editor(post_id: Option<i32>) -> Element {
|
|||||||
// h-[60vh]:随窗口高度自适应;min-h-[400px]:窗口过矮时仍可用。
|
// h-[60vh]:随窗口高度自适应;min-h-[400px]:窗口过矮时仍可用。
|
||||||
div { class: "h-[60vh] min-h-[400px] flex flex-col my-4",
|
div { class: "h-[60vh] min-h-[400px] flex flex-col my-4",
|
||||||
div {
|
div {
|
||||||
class: "flex-1 min-h-0 w-full border border-[var(--color-paper-border)] rounded-xl overflow-hidden bg-[var(--color-paper-entry)] shadow-[0_2px_8px_rgba(0,0,0,0.04)] dark:shadow-none",
|
class: "relative group flex-1 min-h-0 w-full border border-[var(--color-paper-border)] rounded-xl overflow-hidden bg-[var(--color-paper-entry)] shadow-[0_2px_8px_rgba(0,0,0,0.04)] dark:shadow-none",
|
||||||
id: "tiptap-editor",
|
id: "tiptap-editor",
|
||||||
|
img {
|
||||||
|
src: "/images/xiantiaoxiaogou_03.webp",
|
||||||
|
alt: "",
|
||||||
|
class: "absolute bottom-1.5 right-1.5 opacity-60 group-focus-within:opacity-10 transition-opacity duration-300 pointer-events-none z-0",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,9 +661,7 @@ fn CoverUploader(cover_image: Signal<String>, cover_uploading: Signal<bool>) ->
|
|||||||
// —— 上传中:骨架占位 + 文案 ——
|
// —— 上传中:骨架占位 + 文案 ——
|
||||||
if cover_uploading() {
|
if cover_uploading() {
|
||||||
div { class: "absolute inset-0 flex flex-col items-center justify-center gap-3 bg-[var(--color-paper-tertiary)]/30 animate-pulse",
|
div { class: "absolute inset-0 flex flex-col items-center justify-center gap-3 bg-[var(--color-paper-tertiary)]/30 animate-pulse",
|
||||||
span { class: "text-sm text-[var(--color-paper-secondary)]",
|
span { class: "text-sm text-[var(--color-paper-secondary)]", "上传中..." }
|
||||||
"上传中..."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -712,9 +715,7 @@ fn CoverUploader(cover_image: Signal<String>, cover_uploading: Signal<bool>) ->
|
|||||||
}
|
}
|
||||||
// 底部渐变遮罩 + "更换封面"提示(hover 出现)。
|
// 底部渐变遮罩 + "更换封面"提示(hover 出现)。
|
||||||
div { class: "absolute inset-x-0 bottom-0 h-12 bg-gradient-to-t from-black/50 to-transparent opacity-0 group-hover/cover:opacity-100 transition-opacity flex items-end justify-center pb-2 pointer-events-none",
|
div { class: "absolute inset-x-0 bottom-0 h-12 bg-gradient-to-t from-black/50 to-transparent opacity-0 group-hover/cover:opacity-100 transition-opacity flex items-end justify-center pb-2 pointer-events-none",
|
||||||
span { class: "text-xs text-white/90",
|
span { class: "text-xs text-white/90", "点击下方区域可重新上传" }
|
||||||
"点击下方区域可重新上传"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,7 @@ fn TagsContent() -> Element {
|
|||||||
rsx! {
|
rsx! {
|
||||||
EmptyState {
|
EmptyState {
|
||||||
title: "暂无标签",
|
title: "暂无标签",
|
||||||
description: "当前还没有任何标签。"
|
description: "当前还没有任何标签。",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -76,7 +76,9 @@ fn TagsContent() -> Element {
|
|||||||
tag: tag.name.clone(),
|
tag: tag.name.clone(),
|
||||||
},
|
},
|
||||||
"{tag.name}"
|
"{tag.name}"
|
||||||
sup { class: "ml-1 text-sm text-paper-secondary", "{tag.post_count}" }
|
sup { class: "ml-1 text-sm text-paper-secondary",
|
||||||
|
"{tag.post_count}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +132,7 @@ fn TagDetailContent(tag: String) -> Element {
|
|||||||
rsx! {
|
rsx! {
|
||||||
EmptyState {
|
EmptyState {
|
||||||
title: "暂无文章",
|
title: "暂无文章",
|
||||||
description: "该标签下还没有发布任何文章。"
|
description: "该标签下还没有发布任何文章。",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -41,10 +41,21 @@ static GLOBAL_GENERATION: LazyLock<AtomicU64> = LazyLock::new(AtomicU64::default
|
|||||||
pub struct SsrGeneration(pub u64);
|
pub struct SsrGeneration(pub u64);
|
||||||
|
|
||||||
/// 原子递增并返回新的全局世代号。
|
/// 原子递增并返回新的全局世代号。
|
||||||
|
///
|
||||||
|
/// 任何文章写入操作都会调用本函数,标记 SSR 渲染结果已过期。当前 Dioxus 0.7
|
||||||
|
/// 不读取此世代号(详见模块文档),实际失效仍依赖 `SSR_CACHE_SECS` 兜底 TTL。
|
||||||
|
/// 此处打一条 info 日志,既证明写入路径已执行,也提醒部署者此处存在滞后——
|
||||||
|
/// 避免"我改了文章怎么没变"被误判成 DB/发布链路问题。
|
||||||
pub fn bump_global_generation() -> u64 {
|
pub fn bump_global_generation() -> u64 {
|
||||||
GLOBAL_GENERATION
|
let new = GLOBAL_GENERATION
|
||||||
.fetch_add(1, Ordering::SeqCst)
|
.fetch_add(1, Ordering::SeqCst)
|
||||||
.wrapping_add(1)
|
.wrapping_add(1);
|
||||||
|
tracing::info!(
|
||||||
|
new_generation = new,
|
||||||
|
"SSR 世代号已递增(写入路径触发)。注意:Dioxus 0.7 不读取此值,\
|
||||||
|
SSR 缓存需等待 SSR_CACHE_SECS 过期后才反映新内容"
|
||||||
|
);
|
||||||
|
new
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 返回当前全局世代号。
|
/// 返回当前全局世代号。
|
||||||
|
|||||||
11
src/theme.rs
11
src/theme.rs
@ -181,15 +181,14 @@ pub fn ThemeToggle() -> Element {
|
|||||||
let x = coords.x;
|
let x = coords.x;
|
||||||
let y = coords.y;
|
let y = coords.y;
|
||||||
// JS 从 DOM 现状推导目标主题(不传 isDark),避免与 Signal 状态不同步。
|
// JS 从 DOM 现状推导目标主题(不传 isDark),避免与 Signal 状态不同步。
|
||||||
let _ = js_sys::eval(&format!(
|
let _ = js_sys::eval(
|
||||||
|
&format!(
|
||||||
"if (window.__startThemeTransition) \
|
"if (window.__startThemeTransition) \
|
||||||
window.__startThemeTransition({x}, {y});",
|
window.__startThemeTransition({x}, {y});", // theme.set 推迟到动画结束:其触发的 Dioxus 微任务重渲染会打断 VT。
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
));
|
),
|
||||||
// theme.set 推迟到动画结束:其触发的 Dioxus 微任务重渲染会打断 VT。
|
);
|
||||||
// gen 确保连续点击只有最新回调 set。JS 已自治切换 dark class,
|
|
||||||
// 动画完成后再更新 Dioxus 状态,避免组件重渲染可能带来的干扰
|
|
||||||
let gen = click_gen() + 1;
|
let gen = click_gen() + 1;
|
||||||
click_gen.set(gen);
|
click_gen.set(gen);
|
||||||
let mut theme_clone = theme;
|
let mut theme_clone = theme;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user