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

Reactive re-run does not trigger for function defining HypertextLiteral result #2838

Open
lukavdplas opened this issue Mar 2, 2024 · 4 comments
Labels
bug Something isn't working macro Julia macros: @oops reactivity The Pluto programming paradigm

Comments

@lukavdplas
Copy link
Contributor

I was working on a notebook that creates a function with HypertextLiteral.Result output. This is intended to create an interactive HTML element with Javascript.

A minimal version is something like this:

https://gist.github.com/lukavdplas/ebf28806752fba4cb999e0e3c573dc1a

where there is a cell

function mybutton()
	return @htl """
	<div>
		<button>I'm a button!</button>
		<script>
			var parent = currentScript.parentElement;
			var button = parent.querySelector("button");
			
			button.addEventListener("click", (e) => {
				button.innerText = "I have been clicked!"
			});
		</script>
	</div>
	"""
end

and a cell

@bind a mybutton()

I'm adding this simplified version for the sake of clarity, but I could not replicate the issue there. The actual notebook is this one: https://github.com/lukavdplas/PlutoMapPicker.jl/blob/main/src/map-picker.jl

The linked notebook defines two such functions MapPicker() and MapPickerMultiple(), which follow the same principle as the example above, but with much bigger functions.

The issue I encountered is that when I update the HTML (or Javascript) in the function body of MapPicker() or MapPickerMultiple(), the cell with the function call (@bind place MapPicker()) does not seem to re-run. It still shows the "old" version of the output. I need to manually hit Shift + Enter in the cell with the function call to get it to update.

Strangely enough, the dependency also seems broken in the other direction, The notebook contains a cell that defines a struct TileLayer, that is used in the body of MapPicker() and MapPickerMultiple(), and one "normal" Julia cell. When I rename TileLayer so any references to it should break, the "normal" cell" immediately shows an error, but the cells defining MapPicker() and MapPickerMultiple() don't react until I use Shift + Enter to rerun them.

Another weird issue that may or may not be related is that re-running the cell with the function definition for MapPickerMultiple() seems to somehow cause duplicates in the cell output that shows the docstring:

screenshot of docstring cell output

I encountered this in a different notebook a few weeks ago, which had a similar structure: a function that defines a sizable HypertextLiteral.Result. So it doesn't seem to be a one-off, but both notebooks were written by me, so they might have the same "quirk".

(I am using: Pluto, v0.19.38 / Julia 1.6)

@Pangoraw
Copy link
Collaborator

Pangoraw commented Mar 4, 2024

I'm adding this simplified version for the sake of clarity, but I could not replicate the issue there. The actual notebook is this one: https://github.com/lukavdplas/PlutoMapPicker.jl/blob/main/src/map-picker.jl

This can be caused by docstrings + @htl macro (as in #2811) ?

@Pangoraw Pangoraw added bug Something isn't working reactivity The Pluto programming paradigm macro Julia macros: @oops labels Mar 4, 2024
@lukavdplas
Copy link
Contributor Author

Ah, yes, it looks like the issue reported there is caused by the same underlying issue. I'll check if I can get a minimum working example by combining docstrings + @htl.

@lukavdplas
Copy link
Contributor Author

Indeed, the combination of docstrings and @htl seems to cause the issue!

Updated MWE

Here is that notebook after I open it:

image

After I change the return value of the function:

image

So the issue is:

  • the docstring of the function is shown twice.
  • the text in the cell calling myhypertext() hasn't updated.

Thanks, this at least helped me find a work-around: you can comment out docstrings while working on the body of the function. That's not really a fix, just a tip for anyone else running into the same issue.

@fonsp
Copy link
Owner

fonsp commented Mar 7, 2024

Workaround in JuliaPluto/PlutoDependencyExplorer.jl#9

VEZY added a commit to VEZY/STICS-IC-paper that referenced this issue Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macro Julia macros: @oops reactivity The Pluto programming paradigm
Projects
None yet
Development

No branches or pull requests

3 participants