werpu / jsfs_js_ts

Apache License 2.0
2 stars 1 forks source link

test: tobago sheet with style tag #35

Closed henningn closed 1 year ago

henningn commented 1 year ago

The style tag must be within the sheet and NOT in the element of the page.

Expected HTML after ajax:

<html>
<head>
  ...
</head>
<body>
...
<tobago-sheet ...>
  <style nonce='nonceValue' id='page:s1:j_id_4'>#page\:s1 {max-height: 500px;}</style>
  ...
</tobago-sheet>
</body>
</html>

But it is:

<html>
<head>
  ...
  <style nonce id='page:s1:j_id_4'>#page\:s1 {max-height: 500px;}</style>
</head>
<body>
...
<tobago-sheet ...>
  ...
</tobago-sheet>
</body>
</html>
werpu commented 1 year ago

This is indeed a bug... The problem was or is, that for execution of embedded scripts and styles... the content must be appended to the header and then removed (not sure whether this also applies to css, I need to test that) The code does this and the result is there, but I did not take into consideration that some code might rely on those dynamic script and style tags to be present in the page. I will fix that (or check the changes and apply them properly)

Thanks for the tests and for the bug report!


Additional info, I ran a quick test... style elements can stay in place, no need for the head appendix method, but the elements must be generated via document.createElement innerHTML does not suffice in this case... So we can use innerHTML to get the elements in, but they wont be evaled... for a proper evaluation we still must use document.createElement and then append the element! A strategy probably would be to walk over the replaced style elements after innerHTML and then replace the existing ones with newly created ones with the same content and remove the old ones!

werpu commented 1 year ago
image

Thanks test is failing as expected... will start to work an a proper fix for this issue

werpu commented 1 year ago

the solution even simplifies the code, which is welcome, I will issue a new version soon!

I need to check another issue <script type="module" atm not is evaluated by the ajax part as it seems)