ripple 0.3.72 → 0.3.76
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/CHANGELOG.md +116 -0
- package/package.json +3 -3
- package/src/jsx-runtime.d.ts +4 -10
- package/src/runtime/dynamic-client.js +33 -0
- package/src/runtime/dynamic-server.js +80 -0
- package/src/runtime/index-client.js +5 -13
- package/src/runtime/index-server.js +2 -0
- package/src/runtime/internal/client/blocks.js +6 -27
- package/src/runtime/internal/client/composite.js +11 -6
- package/src/runtime/internal/client/for.js +80 -5
- package/src/runtime/internal/client/index.js +0 -2
- package/src/runtime/internal/client/render.js +5 -2
- package/src/runtime/internal/client/types.d.ts +0 -10
- package/src/runtime/internal/server/index.js +8 -1
- package/tests/client/__snapshots__/computed-properties.test.tsrx.snap +8 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +22 -0
- package/tests/client/__snapshots__/html.test.tsrx.snap +4 -0
- package/tests/client/array/array.copy-within.test.tsrx +19 -19
- package/tests/client/array/array.derived.test.tsrx +97 -109
- package/tests/client/array/array.iteration.test.tsrx +28 -28
- package/tests/client/array/array.mutations.test.tsrx +68 -68
- package/tests/client/array/array.static.test.tsrx +82 -92
- package/tests/client/array/array.to-methods.test.tsrx +15 -15
- package/tests/client/async-suspend.test.tsrx +180 -179
- package/tests/client/basic/__snapshots__/basic.attributes.test.tsrx.snap +2 -0
- package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +4 -0
- package/tests/client/basic/basic.attributes.test.tsrx +273 -317
- package/tests/client/basic/basic.collections.test.tsrx +55 -61
- package/tests/client/basic/basic.components.test.tsrx +198 -220
- package/tests/client/basic/basic.errors.test.tsrx +70 -76
- package/tests/client/basic/basic.events.test.tsrx +80 -85
- package/tests/client/basic/basic.get-set.test.tsrx +54 -64
- package/tests/client/basic/basic.hmr.test.tsrx +15 -19
- package/tests/client/basic/basic.reactivity.test.tsrx +121 -135
- package/tests/client/basic/basic.rendering.test.tsrx +273 -178
- package/tests/client/basic/basic.styling.test.tsrx +16 -14
- package/tests/client/basic/basic.utilities.test.tsrx +8 -10
- package/tests/client/boundaries.test.tsrx +18 -18
- package/tests/client/compiler/compiler.assignments.test.tsrx +77 -76
- package/tests/client/compiler/compiler.attributes.test.tsrx +18 -14
- package/tests/client/compiler/compiler.basic.test.tsrx +357 -288
- package/tests/client/compiler/compiler.regex.test.tsrx +40 -44
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +57 -38
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
- package/tests/client/compiler/compiler.typescript.test.tsrx +4 -3
- package/tests/client/composite/composite.dynamic-components.test.tsrx +62 -47
- package/tests/client/composite/composite.generics.test.tsrx +165 -167
- package/tests/client/composite/composite.props.test.tsrx +66 -74
- package/tests/client/composite/composite.reactivity.test.tsrx +132 -166
- package/tests/client/composite/composite.render.test.tsrx +92 -101
- package/tests/client/computed-properties.test.tsrx +14 -18
- package/tests/client/context.test.tsrx +14 -18
- package/tests/client/css/global-additional-cases.test.tsrx +493 -439
- package/tests/client/css/global-advanced-selectors.test.tsrx +169 -153
- package/tests/client/css/global-at-rules.test.tsrx +71 -66
- package/tests/client/css/global-basic.test.tsrx +105 -98
- package/tests/client/css/global-classes-ids.test.tsrx +128 -114
- package/tests/client/css/global-combinators.test.tsrx +83 -78
- package/tests/client/css/global-complex-nesting.test.tsrx +134 -120
- package/tests/client/css/global-edge-cases.test.tsrx +138 -120
- package/tests/client/css/global-keyframes.test.tsrx +108 -96
- package/tests/client/css/global-nested.test.tsrx +88 -78
- package/tests/client/css/global-pseudo.test.tsrx +104 -98
- package/tests/client/css/global-scoping.test.tsrx +145 -125
- package/tests/client/css/style-identifier.test.tsrx +65 -72
- package/tests/client/date.test.tsrx +83 -83
- package/tests/client/dynamic-elements.test.tsrx +318 -299
- package/tests/client/events.test.tsrx +252 -266
- package/tests/client/for.test.tsrx +120 -127
- package/tests/client/head.test.tsrx +74 -48
- package/tests/client/html.test.tsrx +37 -49
- package/tests/client/input-value.test.tsrx +1125 -1354
- package/tests/client/lazy-array.test.tsrx +10 -16
- package/tests/client/lazy-destructuring.test.tsrx +169 -221
- package/tests/client/map.test.tsrx +39 -41
- package/tests/client/media-query.test.tsrx +15 -19
- package/tests/client/object.test.tsrx +46 -56
- package/tests/client/portal.test.tsrx +31 -37
- package/tests/client/ref.test.tsrx +173 -193
- package/tests/client/return.test.tsrx +62 -37
- package/tests/client/set.test.tsrx +33 -33
- package/tests/client/svg.test.tsrx +197 -216
- package/tests/client/switch.test.tsrx +201 -191
- package/tests/client/track-async-hydration.test.tsrx +14 -18
- package/tests/client/tracked-index-access.test.tsrx +18 -28
- package/tests/client/try.test.tsrx +494 -619
- package/tests/client/tsx.test.tsrx +286 -292
- package/tests/client/typescript-generics.test.tsrx +121 -129
- package/tests/client/url/url.derived.test.tsrx +21 -25
- package/tests/client/url/url.parsing.test.tsrx +35 -35
- package/tests/client/url/url.partial-removal.test.tsrx +32 -32
- package/tests/client/url/url.reactivity.test.tsrx +68 -72
- package/tests/client/url/url.serialization.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +21 -27
- package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +16 -16
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +37 -37
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +56 -60
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +32 -34
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +9 -9
- package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +10 -10
- package/tests/hydration/compiled/client/basic.js +390 -319
- package/tests/hydration/compiled/client/composite.js +52 -44
- package/tests/hydration/compiled/client/for.js +734 -604
- package/tests/hydration/compiled/client/head.js +183 -103
- package/tests/hydration/compiled/client/html.js +93 -86
- package/tests/hydration/compiled/client/if-children.js +95 -71
- package/tests/hydration/compiled/client/if.js +113 -89
- package/tests/hydration/compiled/client/mixed-control-flow.js +225 -209
- package/tests/hydration/compiled/client/nested-control-flow.js +94 -98
- package/tests/hydration/compiled/client/reactivity.js +26 -24
- package/tests/hydration/compiled/client/return.js +8 -42
- package/tests/hydration/compiled/client/switch.js +208 -173
- package/tests/hydration/compiled/client/track-async-serialization.js +176 -128
- package/tests/hydration/compiled/client/try.js +29 -21
- package/tests/hydration/compiled/server/basic.js +210 -221
- package/tests/hydration/compiled/server/composite.js +13 -14
- package/tests/hydration/compiled/server/for.js +427 -444
- package/tests/hydration/compiled/server/head.js +199 -189
- package/tests/hydration/compiled/server/html.js +33 -41
- package/tests/hydration/compiled/server/if-children.js +114 -117
- package/tests/hydration/compiled/server/if.js +77 -83
- package/tests/hydration/compiled/server/mixed-control-flow.js +145 -150
- package/tests/hydration/compiled/server/nested-control-flow.js +10 -0
- package/tests/hydration/compiled/server/reactivity.js +24 -22
- package/tests/hydration/compiled/server/return.js +6 -18
- package/tests/hydration/compiled/server/switch.js +179 -176
- package/tests/hydration/compiled/server/track-async-serialization.js +88 -70
- package/tests/hydration/compiled/server/try.js +31 -35
- package/tests/hydration/components/basic.tsrx +216 -258
- package/tests/hydration/components/composite.tsrx +32 -42
- package/tests/hydration/components/events.tsrx +81 -101
- package/tests/hydration/components/for.tsrx +270 -336
- package/tests/hydration/components/head.tsrx +43 -39
- package/tests/hydration/components/hmr.tsrx +16 -22
- package/tests/hydration/components/html-in-template.tsrx +15 -21
- package/tests/hydration/components/html.tsrx +442 -526
- package/tests/hydration/components/if-children.tsrx +107 -125
- package/tests/hydration/components/if.tsrx +68 -90
- package/tests/hydration/components/mixed-control-flow.tsrx +65 -72
- package/tests/hydration/components/nested-control-flow.tsrx +202 -216
- package/tests/hydration/components/portal.tsrx +33 -41
- package/tests/hydration/components/reactivity.tsrx +26 -34
- package/tests/hydration/components/return.tsrx +4 -6
- package/tests/hydration/components/switch.tsrx +73 -78
- package/tests/hydration/components/track-async-serialization.tsrx +83 -93
- package/tests/hydration/components/try.tsrx +37 -51
- package/tests/hydration/switch.test.js +8 -8
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +117 -162
- package/tests/server/basic.components.test.tsrx +164 -194
- package/tests/server/basic.test.tsrx +299 -199
- package/tests/server/compiler.test.tsrx +142 -72
- package/tests/server/composite.props.test.tsrx +54 -58
- package/tests/server/composite.test.tsrx +165 -167
- package/tests/server/context.test.tsrx +13 -17
- package/tests/server/dynamic-elements.test.tsrx +147 -148
- package/tests/server/for.test.tsrx +115 -84
- package/tests/server/head.test.tsrx +54 -31
- package/tests/server/html-nesting-validation.test.tsrx +16 -8
- package/tests/server/if.test.tsrx +49 -59
- package/tests/server/lazy-destructuring.test.tsrx +288 -366
- package/tests/server/return.test.tsrx +58 -36
- package/tests/server/streaming-ssr.test.tsrx +4 -4
- package/tests/server/style-identifier.test.tsrx +61 -69
- package/tests/server/switch.test.tsrx +89 -97
- package/tests/server/track-async-serialization.test.tsrx +85 -103
- package/tests/server/try.test.tsrx +275 -360
- package/tests/utils/ref-types.test.js +72 -0
- package/tests/utils/vite-plugin-config.test.js +41 -74
- package/types/index.d.ts +29 -4
- package/src/runtime/internal/client/compat.js +0 -40
- package/tests/utils/compiler-compat-config.test.js +0 -38
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type { PropsWithExtras } from 'ripple';
|
|
2
|
-
import { createRefKey, track } from 'ripple';
|
|
1
|
+
import type { DynamicProps, PropsWithExtras, TSRXElement } from 'ripple';
|
|
2
|
+
import { createRefKey, Dynamic, track } from 'ripple';
|
|
3
3
|
|
|
4
4
|
describe('server dynamic DOM elements', () => {
|
|
5
5
|
it('renders static dynamic element', async () => {
|
|
6
|
-
function App() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<@tag>{'Hello World'}</@tag>
|
|
10
|
-
</>;
|
|
6
|
+
function App() @{
|
|
7
|
+
let tag = track('div');
|
|
8
|
+
<Dynamic is={tag}>{'Hello World'}</Dynamic>
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
const { body } = await render(App);
|
|
@@ -15,15 +13,11 @@ describe('server dynamic DOM elements', () => {
|
|
|
15
13
|
expect(body).toBeHtml('<div>Hello World</div>');
|
|
16
14
|
});
|
|
17
15
|
|
|
18
|
-
// The ts errors below are due to limitations in our current tsx generation for dynamic elements.
|
|
19
|
-
// They can be ignored for now. But we'll fix them via jsx() vs <jsx>
|
|
20
16
|
it('renders static dynamic element from a plain object with a tracked property', async () => {
|
|
21
|
-
function App() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<@tag>{'Hello World'}</@tag>
|
|
26
|
-
</>;
|
|
17
|
+
function App() @{
|
|
18
|
+
let obj = { tag: track('div') };
|
|
19
|
+
let tag = obj.tag;
|
|
20
|
+
<Dynamic is={tag}>{'Hello World'}</Dynamic>
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
const { body } = await render(App);
|
|
@@ -31,13 +25,30 @@ describe('server dynamic DOM elements', () => {
|
|
|
31
25
|
expect(body).toBeHtml('<div>Hello World</div>');
|
|
32
26
|
});
|
|
33
27
|
|
|
28
|
+
it('does not pass is to dynamic component props', async () => {
|
|
29
|
+
function Child(props: Omit<DynamicProps<'div'>, 'is'> & {
|
|
30
|
+
label: string;
|
|
31
|
+
is?: Function;
|
|
32
|
+
}): TSRXElement<'div'> @{
|
|
33
|
+
<div>
|
|
34
|
+
{props.is === undefined && !('is' in props) ? 'hidden' : 'leaked'}
|
|
35
|
+
</div>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function App() @{
|
|
39
|
+
<Dynamic is={Child} label="child" class="yo" />
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { body } = await render(App);
|
|
43
|
+
|
|
44
|
+
expect(body).toBeHtml('<div>hidden</div>');
|
|
45
|
+
});
|
|
46
|
+
|
|
34
47
|
it('renders static dynamic element from a tracked object with a tracked property', async () => {
|
|
35
|
-
function App() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<@tag>{'Hello World'}</@tag>
|
|
40
|
-
</>;
|
|
48
|
+
function App() @{
|
|
49
|
+
let obj = track({ tag: track('div') });
|
|
50
|
+
let tag = obj.value.tag;
|
|
51
|
+
<Dynamic is={tag}>{'Hello World'}</Dynamic>
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
const { body } = await render(App);
|
|
@@ -48,12 +59,10 @@ describe('server dynamic DOM elements', () => {
|
|
|
48
59
|
it(
|
|
49
60
|
'renders static dynamic element from a tracked object with a computed tracked property',
|
|
50
61
|
async () => {
|
|
51
|
-
function App() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<@tag>{'Hello World'}</@tag>
|
|
56
|
-
</>;
|
|
62
|
+
function App() @{
|
|
63
|
+
let obj = track({ tag: track('div') });
|
|
64
|
+
let tag = obj.value['tag'];
|
|
65
|
+
<Dynamic is={tag}>{'Hello World'}</Dynamic>
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
const { body } = await render(App);
|
|
@@ -63,11 +72,9 @@ describe('server dynamic DOM elements', () => {
|
|
|
63
72
|
);
|
|
64
73
|
|
|
65
74
|
it('renders self-closing dynamic element', async () => {
|
|
66
|
-
function App() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<@tag type="text" value="test" />
|
|
70
|
-
</>;
|
|
75
|
+
function App() @{
|
|
76
|
+
let tag = track('input');
|
|
77
|
+
<Dynamic is={tag} type="text" value="test" />
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
const { body } = await render(App);
|
|
@@ -76,12 +83,15 @@ describe('server dynamic DOM elements', () => {
|
|
|
76
83
|
});
|
|
77
84
|
|
|
78
85
|
it('handles dynamic element with attributes', async () => {
|
|
79
|
-
function App() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
function App() @{
|
|
87
|
+
let tag = track('div');
|
|
88
|
+
let &[className] = track('test-class');
|
|
89
|
+
<Dynamic
|
|
90
|
+
is={tag}
|
|
91
|
+
class={className}
|
|
92
|
+
id="test"
|
|
93
|
+
data-testid="dynamic-element"
|
|
94
|
+
>{'Content'}</Dynamic>
|
|
85
95
|
}
|
|
86
96
|
const { body } = await render(App);
|
|
87
97
|
const { document } = parseHtml(body);
|
|
@@ -95,14 +105,12 @@ describe('server dynamic DOM elements', () => {
|
|
|
95
105
|
});
|
|
96
106
|
|
|
97
107
|
it('handles nested dynamic elements', async () => {
|
|
98
|
-
function App() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
</@outerTag>
|
|
105
|
-
</>;
|
|
108
|
+
function App() @{
|
|
109
|
+
let outerTag = track('div');
|
|
110
|
+
let innerTag = track('span');
|
|
111
|
+
<Dynamic is={outerTag} class="outer">
|
|
112
|
+
<Dynamic is={innerTag} class="inner">{'Nested content'}</Dynamic>
|
|
113
|
+
</Dynamic>
|
|
106
114
|
}
|
|
107
115
|
const { body } = await render(App);
|
|
108
116
|
const { document } = parseHtml(body);
|
|
@@ -117,14 +125,13 @@ describe('server dynamic DOM elements', () => {
|
|
|
117
125
|
});
|
|
118
126
|
|
|
119
127
|
it('handles dynamic element with class object', async () => {
|
|
120
|
-
function App() {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
</>;
|
|
128
|
+
function App() @{
|
|
129
|
+
let tag = track('div');
|
|
130
|
+
let &[active] = track(true);
|
|
131
|
+
<Dynamic
|
|
132
|
+
is={tag}
|
|
133
|
+
class={{ active: active, 'dynamic-element': true }}
|
|
134
|
+
>{'Element with class object'}</Dynamic>
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
const { body } = await render(App);
|
|
@@ -137,19 +144,16 @@ describe('server dynamic DOM elements', () => {
|
|
|
137
144
|
});
|
|
138
145
|
|
|
139
146
|
it('handles dynamic element with style object', async () => {
|
|
140
|
-
function App() {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
{'Styled dynamic element'}
|
|
151
|
-
</@tag>
|
|
152
|
-
</>;
|
|
147
|
+
function App() @{
|
|
148
|
+
let tag = track('span');
|
|
149
|
+
<Dynamic
|
|
150
|
+
is={tag}
|
|
151
|
+
style={{
|
|
152
|
+
color: 'red',
|
|
153
|
+
fontSize: '16px',
|
|
154
|
+
fontWeight: 'bold',
|
|
155
|
+
}}
|
|
156
|
+
>{'Styled dynamic element'}</Dynamic>
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
const { body } = await render(App);
|
|
@@ -163,16 +167,18 @@ describe('server dynamic DOM elements', () => {
|
|
|
163
167
|
});
|
|
164
168
|
|
|
165
169
|
it('handles dynamic element with spread attributes', async () => {
|
|
166
|
-
function App() {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
170
|
+
function App() @{
|
|
171
|
+
let tag = track('section');
|
|
172
|
+
const attrs = {
|
|
173
|
+
id: 'spread-section',
|
|
174
|
+
'data-testid': 'spread-test',
|
|
175
|
+
class: 'spread-class',
|
|
176
|
+
};
|
|
177
|
+
<Dynamic
|
|
178
|
+
is={tag}
|
|
179
|
+
{...attrs}
|
|
180
|
+
data-extra="additional"
|
|
181
|
+
>{'Element with spread attributes'}</Dynamic>
|
|
176
182
|
}
|
|
177
183
|
const { body } = await render(App);
|
|
178
184
|
const { document } = parseHtml(body);
|
|
@@ -188,18 +194,15 @@ describe('server dynamic DOM elements', () => {
|
|
|
188
194
|
it('handles dynamic element with ref not rendered', async () => {
|
|
189
195
|
let capturedElement: HTMLElement | null = null;
|
|
190
196
|
|
|
191
|
-
function App() {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
{'Element with ref'}
|
|
201
|
-
</@tag>
|
|
202
|
-
</>;
|
|
197
|
+
function App() @{
|
|
198
|
+
let tag = track('article');
|
|
199
|
+
<Dynamic
|
|
200
|
+
is={tag}
|
|
201
|
+
ref={(node: HTMLElement) => {
|
|
202
|
+
capturedElement = node;
|
|
203
|
+
}}
|
|
204
|
+
id="ref-test"
|
|
205
|
+
>{'Element with ref'}</Dynamic>
|
|
203
206
|
}
|
|
204
207
|
|
|
205
208
|
const { body } = await render(App);
|
|
@@ -215,21 +218,19 @@ describe('server dynamic DOM elements', () => {
|
|
|
215
218
|
});
|
|
216
219
|
|
|
217
220
|
it('handles dynamic element with createRefKey in spread', async () => {
|
|
218
|
-
function App() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
<@tag {...dynamicProps}>{'Element with spread ref'}</@tag>
|
|
232
|
-
</>;
|
|
221
|
+
function App() @{
|
|
222
|
+
let tag = track('header');
|
|
223
|
+
function elementRef(node: HTMLElement) {
|
|
224
|
+
// Set an attribute on the element to prove ref was called
|
|
225
|
+
node.setAttribute('data-spread-ref-called', 'true');
|
|
226
|
+
node.setAttribute('data-spread-ref-tag', node.tagName.toLowerCase());
|
|
227
|
+
}
|
|
228
|
+
const dynamicProps = {
|
|
229
|
+
id: 'spread-ref-test',
|
|
230
|
+
class: 'ref-element',
|
|
231
|
+
[createRefKey()]: elementRef,
|
|
232
|
+
};
|
|
233
|
+
<Dynamic is={tag} {...dynamicProps}>{'Element with spread ref'}</Dynamic>
|
|
233
234
|
}
|
|
234
235
|
|
|
235
236
|
const { body } = await render(App);
|
|
@@ -245,16 +246,16 @@ describe('server dynamic DOM elements', () => {
|
|
|
245
246
|
});
|
|
246
247
|
|
|
247
248
|
it('applies scoped CSS to dynamic elements', async () => {
|
|
248
|
-
function App() {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
function App() @{
|
|
250
|
+
let tag = track('div');
|
|
251
|
+
<>
|
|
252
|
+
<Dynamic is={tag} class="test-class">{'Dynamic element'}</Dynamic>
|
|
252
253
|
<style>
|
|
253
254
|
.test-class {
|
|
254
255
|
color: red;
|
|
255
256
|
}
|
|
256
257
|
</style>
|
|
257
|
-
|
|
258
|
+
</>
|
|
258
259
|
}
|
|
259
260
|
|
|
260
261
|
const { body } = await render(App);
|
|
@@ -273,10 +274,10 @@ describe('server dynamic DOM elements', () => {
|
|
|
273
274
|
function DynamicButton(&{ ...rest }: PropsWithExtras<{
|
|
274
275
|
class: string;
|
|
275
276
|
id: string;
|
|
276
|
-
}>) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
}>) @{
|
|
278
|
+
const tag = track('button');
|
|
279
|
+
<>
|
|
280
|
+
<Dynamic is={tag} {...rest}>{rest.class}</Dynamic>
|
|
280
281
|
<style>
|
|
281
282
|
.even {
|
|
282
283
|
background-color: green;
|
|
@@ -285,14 +286,12 @@ describe('server dynamic DOM elements', () => {
|
|
|
285
286
|
background-color: red;
|
|
286
287
|
}
|
|
287
288
|
</style>
|
|
288
|
-
|
|
289
|
+
</>
|
|
289
290
|
}
|
|
290
291
|
|
|
291
|
-
function App() {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
<DynamicButton class={count % 2 ? 'even' : 'odd'} id={count % 2 ? 'even' : 'odd'} />
|
|
295
|
-
</>;
|
|
292
|
+
function App() @{
|
|
293
|
+
let &[count] = track(0);
|
|
294
|
+
<DynamicButton class={count % 2 ? 'even' : 'odd'} id={count % 2 ? 'even' : 'odd'} />
|
|
296
295
|
}
|
|
297
296
|
|
|
298
297
|
const { body } = await render(App);
|
|
@@ -312,18 +311,18 @@ describe('server dynamic DOM elements', () => {
|
|
|
312
311
|
});
|
|
313
312
|
|
|
314
313
|
it('adds scoping class to dynamic elements', async () => {
|
|
315
|
-
function App() {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
314
|
+
function App() @{
|
|
315
|
+
let tag = track('div');
|
|
316
|
+
<>
|
|
317
|
+
<Dynamic is={tag} class="scoped">
|
|
319
318
|
<p>{'Scoped dynamic element'}</p>
|
|
320
|
-
|
|
319
|
+
</Dynamic>
|
|
321
320
|
<style>
|
|
322
321
|
.scoped {
|
|
323
322
|
color: blue;
|
|
324
323
|
}
|
|
325
324
|
</style>
|
|
326
|
-
|
|
325
|
+
</>
|
|
327
326
|
}
|
|
328
327
|
|
|
329
328
|
const { body } = await render(App);
|
|
@@ -341,18 +340,18 @@ describe('server dynamic DOM elements', () => {
|
|
|
341
340
|
async () => {
|
|
342
341
|
// NOTE: We always add the class scoping hash if there is css
|
|
343
342
|
// but the tag selector will be marked as unused if it's not explicitly seen in the template.
|
|
344
|
-
function App() {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
343
|
+
function App() @{
|
|
344
|
+
let tag = track('div');
|
|
345
|
+
<>
|
|
346
|
+
<Dynamic is={tag} class="scoped">
|
|
348
347
|
<p>{'Scoped dynamic element'}</p>
|
|
349
|
-
|
|
348
|
+
</Dynamic>
|
|
350
349
|
<style>
|
|
351
350
|
div {
|
|
352
351
|
color: blue;
|
|
353
352
|
}
|
|
354
353
|
</style>
|
|
355
|
-
|
|
354
|
+
</>
|
|
356
355
|
}
|
|
357
356
|
|
|
358
357
|
const { body } = await render(App);
|
|
@@ -367,8 +366,8 @@ describe('server dynamic DOM elements', () => {
|
|
|
367
366
|
);
|
|
368
367
|
|
|
369
368
|
it('doesn\'t add scoping class to components inside dynamic element', async () => {
|
|
370
|
-
function Child() {
|
|
371
|
-
|
|
369
|
+
function Child() @{
|
|
370
|
+
<>
|
|
372
371
|
<div class="child">
|
|
373
372
|
<p>{'I am a child component'}</p>
|
|
374
373
|
</div>
|
|
@@ -377,22 +376,22 @@ describe('server dynamic DOM elements', () => {
|
|
|
377
376
|
color: blue;
|
|
378
377
|
}
|
|
379
378
|
</style>
|
|
380
|
-
|
|
379
|
+
</>
|
|
381
380
|
}
|
|
382
381
|
|
|
383
|
-
function App() {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
382
|
+
function App() @{
|
|
383
|
+
let tag = track('div');
|
|
384
|
+
<>
|
|
385
|
+
<Dynamic is={tag} class="scoped">
|
|
387
386
|
<p>{'Scoped dynamic element'}</p>
|
|
388
387
|
<Child />
|
|
389
|
-
|
|
388
|
+
</Dynamic>
|
|
390
389
|
<style>
|
|
391
390
|
div {
|
|
392
391
|
color: blue;
|
|
393
392
|
}
|
|
394
393
|
</style>
|
|
395
|
-
|
|
394
|
+
</>
|
|
396
395
|
}
|
|
397
396
|
|
|
398
397
|
const { body } = await render(App);
|
|
@@ -415,8 +414,8 @@ describe('server dynamic DOM elements', () => {
|
|
|
415
414
|
});
|
|
416
415
|
|
|
417
416
|
it('doesn\'t add scoping class to dynamically rendered component', async () => {
|
|
418
|
-
function Child() {
|
|
419
|
-
|
|
417
|
+
function Child() @{
|
|
418
|
+
<>
|
|
420
419
|
<div class="child">
|
|
421
420
|
<p>{'I am a child component'}</p>
|
|
422
421
|
</div>
|
|
@@ -425,19 +424,19 @@ describe('server dynamic DOM elements', () => {
|
|
|
425
424
|
color: green;
|
|
426
425
|
}
|
|
427
426
|
</style>
|
|
428
|
-
|
|
427
|
+
</>
|
|
429
428
|
}
|
|
430
429
|
|
|
431
|
-
function App() {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
430
|
+
function App() @{
|
|
431
|
+
let tag = track(() => Child);
|
|
432
|
+
<>
|
|
433
|
+
<Dynamic is={tag} />
|
|
435
434
|
<style>
|
|
436
435
|
.child {
|
|
437
436
|
color: red;
|
|
438
437
|
}
|
|
439
438
|
</style>
|
|
440
|
-
|
|
439
|
+
</>
|
|
441
440
|
}
|
|
442
441
|
|
|
443
442
|
const { body } = await render(App);
|