Skip to content

Commit f1f9151

Browse files
committed
Flesh out the idea more
1 parent e47a15c commit f1f9151

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

source

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124370,11 +124370,12 @@ partial interface <span>ShadowRoot</span> {
124370124370
};
124371124371

124372124372
dictionary <dfn dictionary>PatchUnsafeOptions</dfn> {
124373-
TrustedTransformStream <dfn dict-member for="PatchUnsafeOptions" data-x="dom-PatchUnsafeOptions-trustedTransformStream">trustedTransformStream</dfn>;
124373+
boolean <dfn dict-member for="PatchUnsafeOptions" data-x="dom-PatchUnsafeOptions-runScripts">runScripts</dfn> = false;
124374124374
};</code></pre>
124375124375

124376124376
<div w-nodev>
124377124377

124378+
<div algorithm>
124378124379
<p><code>Element</code>'s <dfn method for="Element"><code
124379124380
data-x="dom-Element-patchUnsafe">patchUnsafe(<var>options</var>)</code></dfn> method steps
124380124381
are:</p>
@@ -124383,25 +124384,58 @@ dictionary <dfn dictionary>PatchUnsafeOptions</dfn> {
124383124384
<li><p>Let <var>writable</var> be a new WritableStream.</p></li>
124384124385

124385124386
<li>
124386-
<p>If <var>options</var>["<code data-x="dom-PatchUnsafeOptions-trustedTransformStream">trustedTransformStream</code>"] <span data-x="map exists">exists</span>:</p>
124387+
<p>👋 Sketch of the streams setup:</p>
124387124388

124388124389
<ol>
124389-
<li><p>Set <var>writable</var> to the result of piping <var>writable</var> through <var>options</var>["trustedTransformStream"].</p></li>
124390+
<li><p>Incoming chunks must all be of the same type, either strings, bytes, or a trusted types
124391+
wrapper.</p></li>
124392+
124393+
<li>
124394+
<p>Some decisions are made based on the first chunk:</p>
124395+
124396+
<ol>
124397+
<li><p>If it's not a trusted types wrapper and there is a default TT policy, create a
124398+
transform stream using <code data-x="">createTransformStream</code> from the default policy.
124399+
Then pipe chunks through that transform stream.</p></li>
124400+
124401+
<li><p>If it's bytes, create an UTF-8 TextDecoderStream and pipe chunks through that.</p></li>
124402+
124403+
<li><p>TODO: which should happen first? should we allow the TT transform stream to take bytes
124404+
as input, or guarantee that it's strings by then?</p></li>
124405+
</ol>
124406+
</li>
124407+
124408+
<li><p>As chunks are coming through, before handing them to the parser, check that they're all
124409+
of the same type. For trusted types, also check that the chunks are in the same order and not
124410+
duplicated/filtered/reordered.</p></li>
124390124411
</ol>
124391124412
</li>
124392124413

124393124414
<li>
124394-
<p>Otherwise:</p>
124415+
<p>👋 Sketch of the parser setup:</p>
124395124416

124396124417
<ol>
124397-
<li><p>If there's a default TT policy, use that and wrap <var>writable</var> 👋</p></li>
124418+
<li><p>Let <var>parser</var> be a new fragment parser.</p></li>
124419+
124420+
<li><p>Add <span>this</span> to the <span>stack of open elements</span>.</p></li>
124421+
124422+
<li><p>If <var>options</var>["<code data-x="dom-PatchUnsafeOptions-runScripts">runScripts</code>"],
124423+
don't mark scripts as already executed.</p></li>
124424+
124425+
<li><p>Write chunks into the parser as they are written to <var>writable</var>.</p></li>
124426+
124427+
<li><p>When a <code>template</code> element with a <code data-x="">patchfor</code> attribute
124428+
comes out of the parser, find the target node by ID and set that as the parser's insertion
124429+
point.</p></li>
124430+
124431+
<li><p>The first time an element is patched, replace all children. Subsequent patches to the
124432+
same target append children.</p></li>
124398124433
</ol>
124399124434
</li>
124400124435

124401-
<li><p>Create a new parser and do all the actual work 👋</p></li>
124402-
124403124436
<li><p>Return <var>writable</var>.</p></li>
124404124437
</ol>
124438+
</div>
124405124439

124406124440
<div class="example">
124407124441
<p>Do a thing like this:</p>
@@ -124416,19 +124450,21 @@ dictionary <dfn dictionary>PatchUnsafeOptions</dfn> {
124416124450
}
124417124451
});
124418124452

124419-
const trustedTransformStream = policy.createTransformStream(input);
124420-
const writable = element.patchUnsafe({ trustedTransformStream });
124421124453
const response = await fetch('/fragments/something');
124422-
response.body.pipeTo(writable);</code></pre>
124454+
const transform = policy.createTransformStream();
124455+
const writable = element.patchUnsafe();
124456+
await response.body.pipeThrough(transform).pipeTo(writable);</code></pre>
124423124457
</div>
124424124458

124459+
<div algorithm>
124425124460
<p><code>ShadowRoot</code>'s <dfn method for="ShadowRoot"><code
124426124461
data-x="dom-ShadowRoot-patchUnsafe">patchUnsafe(<var>options</var>)</code></dfn> method steps
124427124462
are:</p>
124428124463

124429124464
<ol>
124430124465
<li>TODO</li>
124431124466
</ol>
124467+
</div>
124432124468

124433124469
</div>
124434124470

0 commit comments

Comments
 (0)