widgetti / solara

A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps
https://solara.dev
MIT License
1.62k stars 105 forks source link

fix[docs]: solara.Meta elements insert empty span into DOM #625

Open iisakkirotko opened 2 weeks ago

iisakkirotko commented 2 weeks ago

The insertion of <span></span> into the dom is what causes strange extra spacing at the top of notebook-based tutorials with solara.Meta tags currently:

image

Fixes #626

TODO:

iisakkirotko commented 2 weeks ago

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @iisakkirotko and the rest of your teammates on Graphite Graphite

mariobuikhuizen commented 2 weeks ago

Why is this a problem? Why is the span even needed?

iisakkirotko commented 2 weeks ago

@mariobuikhuizen This is what causes the extra spacing at the top of notebook-based tutorials with solara.Meta tags currently:

image

Granted this happens because these spans get inserted into a flex-box with some gaps defined, so not using that could be an alternative solution. The spans seem to be necessary because Vue does not like empty templates, those throw two errors saying:

[Vue warn]: Error compiling template:
Cannot use <template> as component root element because it may contain multiple nodes.

and

[Vue warn]: Error compiling template:
Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
mariobuikhuizen commented 2 weeks ago

@mariobuikhuizen This is what causes the extra spacing at the top of notebook-based tutorials with solara.Meta tags

This would be a better title for the commit/PR.

The spans seem to be necessary because Vue does not like empty templates, those throw two errors

Strange, I never noticed an error with an empty template.

mariobuikhuizen commented 2 weeks ago

Ok, I checked it, I write empty templates like this:

<template>
</template>

This produces no errors.

Doing it like this:

<template></template>

Does produce the second error you mentioned.

mariobuikhuizen commented 2 weeks ago

It's a bug in ipyvue that empty template tags on the same line don't work.

iisakkirotko commented 2 weeks ago

Putting the templates on two different lines fixes both errors. What are your thoughts on the PR? In principle this is a breaking change on the UI side (if someone was unknowingly relying on this for spacing, for example), but I think we can sell it as a fix. I could rename it as suggested, but then the scope of the change seems smaller than it might be.