Python script in <py-script> content may render before script execution
See original GitHub issueHi!
Interesting project!
I didn’t try to set it up but looking at getting started it seems that a small browser behavior was overlooked.
Since HTML could render without fully loaded and <script defer>
only executes right before HTML was full loaded, the way the page is set up as suggested in the tutorial means with slow enough connection or large enough script text, browser may render the Python script on the page before JS execution & custom element registration.
One can avoid that by only construct <py-script>
dynamically… but that’s less preferable since people should be able to embed the Python script declaratively in HTML.
The mitigation I can think of is to wrap the Python code in comment blocks (<!-- -->
). This was actually done for JS too, when <script>
was first introduced: web devs were told to wrap JS in comment blocks to avoid old browsers without support of <script>
from putting JS onscreen1. To this day, HTML5 parser could parse and execute JS wrapped in comment.
It would be nice if pyscript can also pull Python code in the comment node child in <py-script>
, other than the text node child, and update the tutorial as such. This would apply to other custom elements as well.
Thanks!
1: I have never encountered a browser that would do that, except for Mobile IE 2 on a really old WinCE device 😅
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top GitHub Comments
That’s true today but I’m entirely sure it needs to be… The main reason (I think) we
<script defer>
now is related to theSvelte
dependency. Right now that dependency is very thin (only for Svelte stores afaict) so, if we replace that with something else, we can avoid deferring.There’s a related discussion around theming that is likely to be close related to this topic and worth mentioning.
I think it’s definitely worth thinking about the best option overall here, considering this issue in the context of the rest. I’m not opposed to setting the rule on a stylesheet, just think we need to consider all aspects. Definitely a great discussion. 😃
I think it’s good to leave closed, but I think it’s more closely related to #810 - that issue is essentially looking to tidy up the solution proposed earlier in this issue.