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

Stricter validation for linking syntax in ReactiveHTML._template #2689

Merged
merged 4 commits into from
Aug 30, 2021

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Aug 30, 2021

Improved validation for #2684

class Slideshow(ReactiveHTML):

    index = param.Integer(default=0)

    _template = '<img src="https://picsum.photos/800/300?image=${index}" onclick="${_callback}"></img>'

    def _callback(self, event):
        self.index += 1

now raises:

ValueError: DOM nodes with an attached callback must declare an id. Found node with onclick callback referencing _callback method. Add an id attribute like this: <img id="img" onclick="${_callback}>...</img>.

and:

    _template = '<img src="https://picsum.photos/800/300?image=${index}"></img>'

raises:

ValueError: DOM node with a linked parameter declaration must declare an id. Found node with the src attribute referencing the index parameter. Either declare an id on the node, i.e. <img id="img" src="https://picsum.photos/800/300?image=${index}">...</img>, or insert the value as a literal: <img src="https://picsum.photos/800/300?image={{index}}">...</img>.

Being stricter about this validation should eliminate a lot of confusion about linked parameters (${parameter}) and literal values ({{ index }}) and also alert that their callbacks won't fire unless they add an id.

@codecov
Copy link

codecov bot commented Aug 30, 2021

Codecov Report

Merging #2689 (d76c313) into master (492f418) will increase coverage by 0.01%.
The diff coverage is 91.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2689      +/-   ##
==========================================
+ Coverage   81.80%   81.82%   +0.01%     
==========================================
  Files         187      187              
  Lines       23847    23878      +31     
==========================================
+ Hits        19509    19537      +28     
- Misses       4338     4341       +3     
Impacted Files Coverage Δ
panel/models/reactive_html.py 80.28% <90.47%> (+1.08%) ⬆️
panel/tests/test_reactive.py 98.68% <92.85%> (-0.38%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 492f418...d76c313. Read the comment docs.

@MarcSkovMadsen
Copy link
Collaborator

Best way to go 👍

@philippjfr philippjfr added this to the 0.12.2 milestone Aug 30, 2021
@philippjfr philippjfr merged commit b4f92fb into master Aug 30, 2021
@philippjfr philippjfr deleted the reactive_html_validation branch August 30, 2021 13:53
philippjfr added a commit that referenced this pull request Sep 1, 2021
* Stricter validation for linking syntax in ReactiveHTML._template

* Add tests

* Update docs

* Clarify child templates
maximlt added a commit that referenced this pull request Sep 16, 2021
* Fix #2631 - handle RuntimeError: dictionary changed size during iteration (#2632)

* Fix #2631 - handle RuntimeError: dictionary changed size during iteration

* Update panel/reactive.py

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>
Co-authored-by: Philipp Rudiger <prudiger@anaconda.com>

* Ensure tests pass in packaged version (#2636)

* Ensure tests pass in packaged version

* Update plotly test

* Add option to hide constant parameters (#2637)

* Add option to hide constant parameters

* Add test

* Add support for bokeh 2.4 (#2644)

* Ensure sessions get distinct files in config (#2646)

* Fix bug when updating Trend data (#2647)

* Enhance templates docs (#2658)

* clarifiy a sentence in the intro

* add a short definition for modal

* update the number of areas

* add links to template reference

* add an image of the 4 template areas

* add a modal section

* add link to the Golden framework

* clarify theming

* Added on_session_destroyed callback (#2659)

* Cleanup

* Ensure sorters are applied correctly after updating Tabulator value (#2639)

* Ensure sorters are applied correctly after updating Tabulator value

* Fix indents

* Add Folium reference notebook (#2672)

* add Folium reference

* clean up notebook

* Fix typo

* clear notebook

* Fix compatibility with bokeh 2.4 DocumentCallbackManager (#2687)

* Fix compatibility with bokeh 2.4 DocumentCallbackManager

* Fix flake

* correctly accessing the filtered dataframe for selection of tabulator… (#2676)

* correctly accessing the filtered dataframe for selection of tabulator #2642

* removing unused fixture

* Ensure threaded servers are killed after test failures (#2688)

* Unpin xarray

* Unescape child literal HTML in ReactiveHTML (#2690)

* Stricter validation for linking syntax in ReactiveHTML._template (#2689)

* Stricter validation for linking syntax in ReactiveHTML._template

* Add tests

* Update docs

* Clarify child templates

* fix-reloading (#2692)

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>

* Ensure Trend indicator can be rendered in layout (#2694)

* Resolve remaining compatibility issues with bokeh 2.4 (#2696)

* resize plot when window resizes (#2704)

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>

* Editable sliders' `name` can be changed (#2678)

* add tests for editable int and float sliders

* add failing tests when updating their name

* prevent the composite layout from using name

The Column/Row wrapping the composite widget inherited the name param
and watched it. This is no longer true, which allows the title of some
composite widgets to be updated.

* Switch binder links to latest version (#2705)

* fix-plotly-mapbox-relayout (#2717)

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>

* Add the version number in the binder badge (#2711)

* Add the version number in the binder badge

Which should help us remember that the link has to be updated after a new release.

* Support assignment operators in ReactiveHTML scripts (#2718)

* Support assignment operators in ReactiveHTML scripts

* Add test

* Fix support for async functions on pn.state.add_periodic_callback (#2737)

* Upgrade to bokeh 2.4 and drop compatibility for older versions (#2739)

* Update changelog

* Fix rebase error

* Fix flake

* Bump panel.js version

* Fix rc version

* Update bokeh versions

Co-authored-by: Marc Skov Madsen <marc.skov.madsen@gmail.com>
Co-authored-by: Marc Skov Madsen <masma@orsted.dk>
Co-authored-by: Maxime Liquet <35924738+maximlt@users.noreply.github.com>
Co-authored-by: Nestor Ghenzi <46707985+nghenzi@users.noreply.github.com>
Co-authored-by: Simon <simonparlow@gmx.net>
Co-authored-by: maximlt <mliquet@anaconda.com>
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