fix: hot-reloading view marker line number (#1255)

This commit is contained in:
Greg Johnston 2023-06-30 14:03:54 -04:00 committed by GitHub
parent 67300adf41
commit 5adc88bf50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 9 deletions

View file

@ -70,7 +70,7 @@ impl ViewMacros {
let mut views = Vec::new();
for view in visitor.views {
let span = view.span();
let id = span_to_stable_id(path, span);
let id = span_to_stable_id(path, span.start().line);
let mut tokens = view.tokens.clone().into_iter();
tokens.next(); // cx
tokens.next(); // ,
@ -148,15 +148,11 @@ impl<'ast> Visit<'ast> for ViewMacroVisitor<'ast> {
}
}
pub fn span_to_stable_id(
path: impl AsRef<Path>,
site: proc_macro2::Span,
) -> String {
pub fn span_to_stable_id(path: impl AsRef<Path>, line: usize) -> String {
let file = path
.as_ref()
.to_str()
.unwrap_or_default()
.replace(['/', '\\'], "-");
let start = site.start();
format!("{}-{:?}", file, start.line)
format!("{file}-{line}")
}

View file

@ -3,7 +3,7 @@ function patch(json) {
try {
const views = JSON.parse(json);
for (const [id, patches] of views) {
console.log("[HOT RELOAD]", patches);
console.log("[HOT RELOAD]", id, patches);
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_COMMENT),
open = `leptos-view|${id}|open`,
close = `leptos-view|${id}|close`;

View file

@ -384,7 +384,7 @@ fn normalized_call_site(site: proc_macro::Span) -> Option<String> {
if #[cfg(all(debug_assertions, feature = "nightly"))] {
Some(leptos_hot_reload::span_to_stable_id(
site.source_file().path(),
site.into()
site.start().line()
))
} else {
_ = site;