question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python script in <py-script> content may render before script execution

See original GitHub issue

Hi!

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fpligercommented, May 13, 2022

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 the Svelte 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. 😃

0reactions
JeffersGlasscommented, Oct 4, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyScript: Way to run Python script in web/browser
<py-repl> : creates a REPL component that is rendered to the page as a code editor and allows users to write code that...
Read more >
Intro to PyScript: Run Python in the browser - LogRocket Blog
Learn how to deploy Python code in the browser using PyScript, a new library that builds of Pyodide and ports CPython to Wasm....
Read more >
Getting Python To Run In Your Browser — Using PyScript
Essentially with python in the browser, your backend code is downloaded once and continues to run in the browser, as JavaScript would. So...
Read more >
A First Look at PyScript: Python in the Web Browser
In this tutorial, you'll learn about PyScript, a new framework that allows for running Python in the web browser with few or no...
Read more >
PyScript Beta Lets You Run Python in the Browser - MakeUseOf
Your Python code sits inside a custom py-script tag within a document's body. The PyScript JavaScript file will then interpret its contents ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found