File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,12 @@ export function assign_payload(p1, p2) {
79
79
p1 . anchor = p2 . anchor ;
80
80
}
81
81
82
+ /**
83
+ * Array of `onDestroy` callbacks that should be called at the end of the server render function
84
+ * @type {Function[] }
85
+ */
86
+ export let on_destroy = [ ] ;
87
+
82
88
/**
83
89
* @param {(...args: any[]) => void } component
84
90
* @param {{ props: Record<string, any>; context?: Map<any, any> } } options
@@ -90,6 +96,8 @@ export function render(component, options) {
90
96
const root_head_anchor = create_anchor ( payload . head ) ;
91
97
92
98
set_is_ssr ( true ) ;
99
+ const prev_on_destroy = on_destroy ;
100
+ on_destroy = [ ] ;
93
101
payload . out += root_anchor ;
94
102
95
103
if ( options . context ) {
@@ -102,6 +110,8 @@ export function render(component, options) {
102
110
$ . pop ( ) ;
103
111
}
104
112
payload . out += root_anchor ;
113
+ for ( const cleanup of on_destroy ) cleanup ( ) ;
114
+ on_destroy = prev_on_destroy ;
105
115
set_is_ssr ( false ) ;
106
116
107
117
return {
Original file line number Diff line number Diff line change
1
+ import { on_destroy } from '../internal/server/index.js' ;
2
+
1
3
export {
2
4
createRoot ,
3
5
createEventDispatcher ,
6
8
getContext ,
7
9
hasContext ,
8
10
mount ,
9
- onDestroy ,
10
11
setContext ,
11
12
tick ,
12
13
untrack
@@ -15,6 +16,11 @@ export {
15
16
/** @returns {void } */
16
17
export function onMount ( ) { }
17
18
19
+ /** @param {Function } fn */
20
+ export function onDestroy ( fn ) {
21
+ on_destroy . push ( fn ) ;
22
+ }
23
+
18
24
/** @returns {void } */
19
25
export function beforeUpdate ( ) { }
20
26
You can’t perform that action at this time.
0 commit comments