1
1
/** @import { ComponentType, SvelteComponent } from 'svelte' */
2
- /** @import { Component, RenderOutput } from '#server' */
2
+ /** @import { RenderOutput, SSRContext } from '#server' */
3
3
/** @import { Store } from '#shared' */
4
4
/** @import { AccumulatedContent } from './payload.js' */
5
5
export { FILENAME , HMR } from '../../constants.js' ;
@@ -14,11 +14,10 @@ import {
14
14
} from '../../constants.js' ;
15
15
import { escape_html } from '../../escaping.js' ;
16
16
import { DEV } from 'esm-env' ;
17
- import { current_component , pop , push } from './context.js' ;
17
+ import { ssr_context , pop , push , set_ssr_context } from './context.js' ;
18
18
import { EMPTY_COMMENT , BLOCK_CLOSE , BLOCK_OPEN , BLOCK_OPEN_ELSE } from './hydration.js' ;
19
19
import { validate_store } from '../shared/validate.js' ;
20
20
import { is_boolean_attribute , is_raw_text_element , is_void } from '../../utils.js' ;
21
- import { reset_elements } from './dev.js' ;
22
21
import { Payload , TreeState } from './payload.js' ;
23
22
import { abort } from './abort-signal.js' ;
24
23
@@ -69,6 +68,8 @@ export let on_destroy = [];
69
68
* @returns {RenderOutput }
70
69
*/
71
70
export function render ( component , options = { } ) {
71
+ var previous_context = ssr_context ;
72
+
72
73
try {
73
74
const payload = new Payload (
74
75
new TreeState ( 'sync' , options . idPrefix ? options . idPrefix + '-' : '' )
@@ -78,16 +79,9 @@ export function render(component, options = {}) {
78
79
on_destroy = [ ] ;
79
80
payload . push ( BLOCK_OPEN ) ;
80
81
81
- let reset_reset_element ;
82
-
83
- if ( DEV ) {
84
- // prevent parent/child element state being corrupted by a bad render
85
- reset_reset_element = reset_elements ( ) ;
86
- }
87
-
88
82
if ( options . context ) {
89
83
push ( ) ;
90
- /** @type {Component } */ ( current_component ) . c = options . context ;
84
+ /** @type {SSRContext } */ ( ssr_context ) . c = options . context ;
91
85
}
92
86
93
87
// @ts -expect-error
@@ -97,10 +91,6 @@ export function render(component, options = {}) {
97
91
pop ( ) ;
98
92
}
99
93
100
- if ( reset_reset_element ) {
101
- reset_reset_element ( ) ;
102
- }
103
-
104
94
payload . push ( BLOCK_CLOSE ) ;
105
95
for ( const cleanup of on_destroy ) cleanup ( ) ;
106
96
on_destroy = prev_on_destroy ;
@@ -121,6 +111,7 @@ export function render(component, options = {}) {
121
111
} ;
122
112
} finally {
123
113
abort ( ) ;
114
+ set_ssr_context ( previous_context ) ;
124
115
}
125
116
}
126
117
@@ -140,6 +131,8 @@ export let async_on_destroy = [];
140
131
* @returns {Promise<RenderOutput> }
141
132
*/
142
133
export async function render_async ( component , options = { } ) {
134
+ var previous_context = ssr_context ;
135
+
143
136
try {
144
137
const payload = new Payload (
145
138
new TreeState ( 'async' , options . idPrefix ? options . idPrefix + '-' : '' )
@@ -149,16 +142,9 @@ export async function render_async(component, options = {}) {
149
142
async_on_destroy = [ ] ;
150
143
payload . push ( BLOCK_OPEN ) ;
151
144
152
- let reset_reset_element ;
153
-
154
- if ( DEV ) {
155
- // prevent parent/child element state being corrupted by a bad render
156
- reset_reset_element = reset_elements ( ) ;
157
- }
158
-
159
145
if ( options . context ) {
160
146
push ( ) ;
161
- /** @type {Component } */ ( current_component ) . c = options . context ;
147
+ /** @type {SSRContext } */ ( ssr_context ) . c = options . context ;
162
148
}
163
149
164
150
// @ts -expect-error
@@ -168,10 +154,6 @@ export async function render_async(component, options = {}) {
168
154
pop ( ) ;
169
155
}
170
156
171
- if ( reset_reset_element ) {
172
- reset_reset_element ( ) ;
173
- }
174
-
175
157
payload . push ( BLOCK_CLOSE ) ;
176
158
for ( const cleanup of async_on_destroy ) cleanup ( ) ;
177
159
async_on_destroy = prev_on_destroy ;
@@ -192,6 +174,7 @@ export async function render_async(component, options = {}) {
192
174
} ;
193
175
} finally {
194
176
abort ( ) ;
177
+ set_ssr_context ( previous_context ) ;
195
178
}
196
179
}
197
180
0 commit comments