Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: adds more helpful text for hydration errors (closes #3267) #3275

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

gbj
Copy link
Collaborator

@gbj gbj commented Nov 22, 2024

Error messages in the case of hydration problems are currently very unhelpful in 0.7, as I had not yet done anything to make them more useful. For example, if the renderer was expected to find an element and found something else instead, you just got an .unwrap() inside HtmlElement::hydrate().

This adds some debugging machinery that attempts to do the following:

  1. Provide a useful error message.
  2. List the location of the view! or element that is currently being hydrated, to help narrow down problems.
  3. Logs out the unexpected node as part of the error message in the JS console. Most browser devtools allow you to right-click and go to where that node is used in the page, which means you can navigate directly to wherever in your application the unexpected node was found.

@gbj gbj merged commit 3de0414 into main Nov 22, 2024
74 checks passed
@gbj gbj deleted the better-hydration-errors branch November 22, 2024 20:10
@Nutomic
Copy link

Nutomic commented Nov 25, 2024

This is much better, thanks! However the line number in the error message is wrong. It always points to the line where the view! macro definition starts, not where inside the macro the error occurs. In my case it always reports an error at src/frontend/components/nav.rs:22:5 which is here, even after adding more lines at the beginning of view!

@gbj
Copy link
Collaborator Author

gbj commented Nov 25, 2024

I am aware that it currently returns the line number of the view macro, rather than the element.

@gbj
Copy link
Collaborator Author

gbj commented Nov 25, 2024

But note that it should also log out the actual DOM node, which you can right-click on to go to its location in the DOM inspector -- which should help narrow it much more than the view line number.

@gbj
Copy link
Collaborator Author

gbj commented Nov 27, 2024

@Nutomic See #3293 for improved error location: now the line/column should point to the actual element in the view, not the view macro as a whole.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants