@fictjs/ssr 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/chunk-DI4PFT6R.js +11 -0
- package/dist/fict-stream-runtime.js +1 -0
- package/dist/index.cjs +383 -67
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +382 -67
- package/dist/stream-runtime.cjs +36 -0
- package/dist/stream-runtime.d.cts +16 -0
- package/dist/stream-runtime.d.ts +16 -0
- package/dist/stream-runtime.js +8 -0
- package/package.json +14 -6
package/README.md
CHANGED
|
@@ -287,6 +287,25 @@ import { renderToStream } from '@fictjs/ssr'
|
|
|
287
287
|
const stream = renderToStream(() => <App />, { mode: 'shell' })
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
+
#### Strict CSP Streaming Runtime
|
|
291
|
+
|
|
292
|
+
For routes that disallow inline patch scripts, serve the packaged classic script
|
|
293
|
+
asset and enable observer patch mode:
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
import { renderToStream } from '@fictjs/ssr'
|
|
297
|
+
|
|
298
|
+
const stream = renderToStream(() => <App />, {
|
|
299
|
+
mode: 'shell',
|
|
300
|
+
streamRuntime: 'external',
|
|
301
|
+
streamRuntimeSrc: '/assets/fict-stream-runtime.js',
|
|
302
|
+
})
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
The asset is published as `@fictjs/ssr/fict-stream-runtime.js`. Build tools that
|
|
306
|
+
need to materialize it themselves can import `createStreamRuntimeCode` from
|
|
307
|
+
`@fictjs/ssr/stream-runtime`.
|
|
308
|
+
|
|
290
309
|
### renderToPipeableStream
|
|
291
310
|
|
|
292
311
|
Node.js-style stream variant (compatible with `pipe()`).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/stream-runtime.ts
|
|
2
|
+
function createStreamRuntimeCode(options = {}) {
|
|
3
|
+
const observerMode = options.observerMode ?? true;
|
|
4
|
+
return `(function(){if(window.__FICT_STREAM)return;var cache=new Map();function find(id){var hit=cache.get(id);if(hit)return hit;var start=null,end=null;var w=document.createTreeWalker(document,NodeFilter.SHOW_COMMENT);while(w.nextNode()){var n=w.currentNode;var d=n.data;if(d==="fict:suspense-start:"+id)start=n;else if(d==="fict:suspense-end:"+id)end=n;if(start&&end)break;}if(start&&end){hit={start:start,end:end};cache.set(id,hit);}return hit;}function apply(id){var tpl=document.querySelector('template[data-fict-suspense="' + id + '"]');if(!tpl)return;var b=find(id);if(!b)return;var node=b.start.nextSibling;while(node&&node!==b.end){var next=node.nextSibling;node.parentNode&&node.parentNode.removeChild(node);node=next;}b.end.parentNode&&b.end.parentNode.insertBefore(tpl.content,b.end);tpl.parentNode&&tpl.parentNode.removeChild(tpl);}window.__FICT_STREAM={apply:apply};` + (observerMode ? 'function scan(root){var list=(root&&root.querySelectorAll?root:document).querySelectorAll("template[data-fict-suspense]");for(var i=0;i<list.length;i++){apply(list[i].getAttribute("data-fict-suspense"));}}if(typeof MutationObserver==="function"){new MutationObserver(function(muts){for(var i=0;i<muts.length;i++){for(var j=0;j<muts[i].addedNodes.length;j++){var n=muts[i].addedNodes[j];if(n.nodeType===1){if(n.matches&&n.matches("template[data-fict-suspense]"))apply(n.getAttribute("data-fict-suspense"));scan(n);}}}}).observe(document.documentElement||document,{childList:true,subtree:true});}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){scan(document);},{once:true});}else{scan(document);}' : "") + "})();";
|
|
5
|
+
}
|
|
6
|
+
var FICT_STREAM_RUNTIME_CODE = createStreamRuntimeCode({ observerMode: true });
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
createStreamRuntimeCode,
|
|
10
|
+
FICT_STREAM_RUNTIME_CODE
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){if(window.__FICT_STREAM)return;var cache=new Map();function find(id){var hit=cache.get(id);if(hit)return hit;var start=null,end=null;var w=document.createTreeWalker(document,NodeFilter.SHOW_COMMENT);while(w.nextNode()){var n=w.currentNode;var d=n.data;if(d==="fict:suspense-start:"+id)start=n;else if(d==="fict:suspense-end:"+id)end=n;if(start&&end)break;}if(start&&end){hit={start:start,end:end};cache.set(id,hit);}return hit;}function apply(id){var tpl=document.querySelector('template[data-fict-suspense="' + id + '"]');if(!tpl)return;var b=find(id);if(!b)return;var node=b.start.nextSibling;while(node&&node!==b.end){var next=node.nextSibling;node.parentNode&&node.parentNode.removeChild(node);node=next;}b.end.parentNode&&b.end.parentNode.insertBefore(tpl.content,b.end);tpl.parentNode&&tpl.parentNode.removeChild(tpl);}window.__FICT_STREAM={apply:apply};function scan(root){var list=(root&&root.querySelectorAll?root:document).querySelectorAll("template[data-fict-suspense]");for(var i=0;i<list.length;i++){apply(list[i].getAttribute("data-fict-suspense"));}}if(typeof MutationObserver==="function"){new MutationObserver(function(muts){for(var i=0;i<muts.length;i++){for(var j=0;j<muts[i].addedNodes.length;j++){var n=muts[i].addedNodes[j];if(n.nodeType===1){if(n.matches&&n.matches("template[data-fict-suspense]"))apply(n.getAttribute("data-fict-suspense"));scan(n);}}}}).observe(document.documentElement||document,{childList:true,subtree:true});}if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){scan(document);},{once:true});}else{scan(document);}})();
|