1
1
import { is_promise , noop } from '../shared/utils.js' ;
2
2
import { subscribe_to_store } from '../../store/utils.js' ;
3
- import {
4
- UNINITIALIZED ,
5
- DOMBooleanAttributes ,
6
- RawTextElements ,
7
- disallowed_paragraph_contents ,
8
- interactive_elements ,
9
- is_tag_valid_with_parent
10
- } from '../../constants.js' ;
3
+ import { UNINITIALIZED , DOMBooleanAttributes , RawTextElements } from '../../constants.js' ;
11
4
import { escape_html } from '../../escaping.js' ;
12
5
import { DEV } from 'esm-env' ;
13
6
import { current_component , pop , push } from './context.js' ;
14
7
import { BLOCK_CLOSE , BLOCK_OPEN } from './hydration.js' ;
15
8
import { validate_store } from '../shared/validate.js' ;
16
9
17
- /**
18
- * @typedef {{
19
- * tag: string;
20
- * parent: null | Element;
21
- * }} Element
22
- */
23
-
24
10
/**
25
11
* @typedef {{
26
12
* head: string;
27
13
* html: string;
28
14
* }} RenderOutput
29
15
*/
30
16
31
- /**
32
- * @typedef {{
33
- * out: string;
34
- * anchor: number;
35
- * head: {
36
- * title: string;
37
- * out: string;
38
- * anchor: number;
39
- * };
40
- * }} Payload
41
- */
42
-
43
17
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
44
18
// https://infra.spec.whatwg.org/#noncharacter
45
19
const INVALID_ATTR_NAME_CHAR_REGEX =
@@ -64,19 +38,14 @@ export const VoidElements = new Set([
64
38
'wbr'
65
39
] ) ;
66
40
67
- /**
68
- * @type {Element | null }
69
- */
70
- let current_element = null ;
71
-
72
- /** @returns {Payload } */
41
+ /** @returns {import('#server').Payload } */
73
42
function create_payload ( ) {
74
43
return { out : '' , head : { title : '' , out : '' , anchor : 0 } , anchor : 0 } ;
75
44
}
76
45
77
46
/**
78
- * @param {Payload } to_copy
79
- * @returns {Payload }
47
+ * @param {import('#server'). Payload } to_copy
48
+ * @returns {import('#server'). Payload }
80
49
*/
81
50
export function copy_payload ( to_copy ) {
82
51
return {
@@ -87,8 +56,8 @@ export function copy_payload(to_copy) {
87
56
88
57
/**
89
58
* Assigns second payload to first
90
- * @param {Payload } p1
91
- * @param {Payload } p2
59
+ * @param {import('#server'). Payload } p1
60
+ * @param {import('#server'). Payload } p2
92
61
* @returns {void }
93
62
*/
94
63
export function assign_payload ( p1 , p2 ) {
@@ -98,59 +67,7 @@ export function assign_payload(p1, p2) {
98
67
}
99
68
100
69
/**
101
- * @param {Payload } payload
102
- * @param {string } message
103
- */
104
- function error_on_client ( payload , message ) {
105
- message =
106
- `Svelte SSR validation error:\n\n${ message } \n\n` +
107
- 'Ensure your components render valid HTML as the browser will try to repair invalid HTML, ' +
108
- 'which may result in content being shifted around and will likely result in a hydration mismatch.' ;
109
- // eslint-disable-next-line no-console
110
- console . error ( message ) ;
111
- payload . head . out += `<script>console.error(\`${ message } \`)</script>` ;
112
- }
113
-
114
- /**
115
- * @param {string } tag
116
- * @param {Payload } payload
117
- */
118
- export function push_element ( tag , payload ) {
119
- if ( current_element !== null && ! is_tag_valid_with_parent ( tag , current_element . tag ) ) {
120
- error_on_client ( payload , `<${ tag } > is invalid inside <${ current_element . tag } >` ) ;
121
- }
122
- if ( interactive_elements . has ( tag ) ) {
123
- let element = current_element ;
124
- while ( element !== null ) {
125
- if ( interactive_elements . has ( element . tag ) ) {
126
- error_on_client ( payload , `<${ tag } > is invalid inside <${ element . tag } >` ) ;
127
- }
128
- element = element . parent ;
129
- }
130
- }
131
- if ( disallowed_paragraph_contents . includes ( tag ) ) {
132
- let element = current_element ;
133
- while ( element !== null ) {
134
- if ( element . tag === 'p' ) {
135
- error_on_client ( payload , `<${ tag } > is invalid inside <p>` ) ;
136
- }
137
- element = element . parent ;
138
- }
139
- }
140
- current_element = {
141
- tag,
142
- parent : current_element
143
- } ;
144
- }
145
-
146
- export function pop_element ( ) {
147
- if ( current_element !== null ) {
148
- current_element = current_element . parent ;
149
- }
150
- }
151
-
152
- /**
153
- * @param {Payload } payload
70
+ * @param {import('#server').Payload } payload
154
71
* @param {string } tag
155
72
* @param {() => void } attributes_fn
156
73
* @param {() => void } children_fn
@@ -214,8 +131,8 @@ export function render(component, options) {
214
131
}
215
132
216
133
/**
217
- * @param {Payload } payload
218
- * @param {(head_payload: Payload['head']) => void } fn
134
+ * @param {import('#server'). Payload } payload
135
+ * @param {(head_payload: import('#server'). Payload['head']) => void } fn
219
136
* @returns {void }
220
137
*/
221
138
export function head ( payload , fn ) {
@@ -239,7 +156,7 @@ export function attr(name, value, boolean) {
239
156
}
240
157
241
158
/**
242
- * @param {Payload } payload
159
+ * @param {import('#server'). Payload } payload
243
160
* @param {boolean } is_html
244
161
* @param {Record<string, string> } props
245
162
* @param {() => void } component
@@ -497,8 +414,8 @@ export async function value_or_fallback_async(value, fallback) {
497
414
}
498
415
499
416
/**
500
- * @param {Payload } payload
501
- * @param {void | ((payload: Payload, props: Record<string, unknown>) => void) } slot_fn
417
+ * @param {import('#server'). Payload } payload
418
+ * @param {void | ((payload: import('#server'). Payload, props: Record<string, unknown>) => void) } slot_fn
502
419
* @param {Record<string, unknown> } slot_props
503
420
* @param {null | (() => void) } fallback_fn
504
421
* @returns {void }
@@ -621,6 +538,8 @@ export function once(get_value) {
621
538
622
539
export { push , pop } from './context.js' ;
623
540
541
+ export { push_element , pop_element } from './dev.js' ;
542
+
624
543
export {
625
544
add_snippet_symbol ,
626
545
validate_component ,
0 commit comments