-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Declarative <script> behavior #7986
Comments
We still have whatwg/dom#808 as well. I was initially thinking that it would be nice to just react to insertion and removal, but the parser complicates that as the moment it's inserted it won't have all of its contents quite yet. That makes me lean toward "dynamic". We should make it clear that only "child text content" is operated on here. We might also need to clarify https://html.spec.whatwg.org/#restrictions-for-contents-of-script-elements further in that |
+1 to leaning toward "dynamic", and to the clarifications @annevk suggests. My tentative plan would be:
Note that for import maps in particular, they currently have a separate element of non-dynamism where their impact on the behavior of JS imports gets locked down the first time a JS import happens. But this can be thought of as a separate mechanism layered on top of the general script processing model. For example:
Note that there is also interest in removing this lock down. So that would be a second stage, after moving import maps to "dynamic" in the sense mentioned here. |
Just to clarify, is this "Dynamic text content" in the longer doc, i.e. to reflect changes to the text content but not to reflect changes to (most of) the other attributes, namely the type attribute? (I assume so)
IIUC the current import maps spec is not like "reset" (re-insertion of |
Also, what do you think of:
(I expect these would largely affect the implementation, and thus my personal preference is "No" and "the latter", respectively, but anyway I'd like to hear first what other people want) |
Yes, by "dynamic" I mean "dynamic text content". In general of the state in the script section I think we would only update the script's result for these types. (I haven't checked every one.)
I prefer "Dynamic text content", not "Dynamic text content without re-insertion support". It's most like
I think the following factoring might be reasonable, at least for inline:
|
Yeah, with the caveat that some additional steps will be needed, at least for "child text content" -- CSP check comes to mind, not sure if it's the only one. |
tl;dr: We should decide how non-JavaScript "declarative script types" should handle removal, insertion after previously being prepared/executed, and in the case of inline scripts, dynamic modification of text content. Establishing a framework for this will help make sure we consciously choose good author, vendor and spec author ergonomics that are as consistent as possible.
Recently a few efforts have been reusing the <script> tag to insert JSON-based declarative syntax into HTML documents:
In addition to these the HTML spec already mentions that
<script>
elements can be used as a data block for author-specific purposes.This allows these features to have an extensible syntax in a format familiar to web developers, with existing tooling, while benefiting from the existing special HTML parser behavior for <script>, notably treating its contents as character data and not constructing child elements. (Not without hazards, notably around when HTML comment syntax occurs midway through script text.)
Some options include:
<script>
element must be used to reinstate it)<style>
)Obviously the scripting section is both complex and security sensitive, and the observable behavior of JavaScript types must not be modified.
Longer document with some prior discussion and comparison.
The text was updated successfully, but these errors were encountered: