Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a698f6

Browse files
authored
renderToPipeableStream: expose errors through onError, no longer emit un-catchable error event on internal stream (#405)
1 parentc819f51 commit0a698f6

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

‎.changeset/mighty-keys-admire.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-render-to-string':patch
3+
---
4+
5+
renderToPipeableStream: expose errors through onError, no longer emit un-catchable error event on internal stream

‎src/stream-node.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface RenderToPipeableStreamOptions {
88
}
99

1010
interfacePipeableStream{
11-
abort:()=>void;
11+
abort:(reason?:unknown)=>void;
1212
pipe:(writable:WritableStream)=>void;
1313
}
1414

‎src/stream-node.js‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,28 @@ export function renderToPipeableStream(vnode, options, context) {
4444
stream.end();
4545
})
4646
.catch((error)=>{
47-
stream.destroy(error);
47+
stream.destroy();
48+
if(options.onError){
49+
options.onError(error);
50+
}else{
51+
throwerror;
52+
}
4853
});
4954

5055
Promise.resolve().then(()=>{
5156
options.onShellReady&&options.onShellReady();
5257
});
5358

5459
return{
55-
abort(){
60+
/**
61+
*@param {unknown} [reason]
62+
*/
63+
abort(reason=newError('The render was aborted by the server without a reason.')){
5664
controller.abort();
57-
stream.destroy(newError('aborted'));
65+
stream.destroy();
66+
if(options.onError){
67+
options.onError(reason);
68+
}
5869
},
5970
/**
6071
*@param {import("stream").Writable} writable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp