Skip to content

Commit 28872c3

Browse files
committed
use shorter notation
1 parent 63015ed commit 28872c3

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ import {
2323
} from './lib/constants.js';
2424

2525
const EMPTY_ARR = [];
26+
const EMPTY_OBJ = {};
2627
const isArray = Array.isArray;
2728
const assign = Object.assign;
29+
const BEGIN_SUSPENSE_DENOMINATOR = '<!--$s-->';
30+
const END_SUSPENSE_DENOMINATOR = '<!--/$s-->';
2831

2932
// Global state for the current render pass
3033
let beforeDiff, afterDiff, renderHook, ummountHook;
@@ -149,10 +152,6 @@ function markAsDirty() {
149152
this.__d = true;
150153
}
151154

152-
const EMPTY_OBJ = {};
153-
const BEGIN_SUSPENSE_DENOMINATOR = '<!-- $s -->';
154-
const END_SUSPENSE_DENOMINATOR = '<!-- /$s -->';
155-
156155
/**
157156
* @param {VNode} vnode
158157
* @param {Record<string, unknown>} context
@@ -373,7 +372,9 @@ function _renderToString(
373372
try {
374373
rendered = type.call(component, props, cctx);
375374
} catch (e) {
376-
if (asyncMode) vnode._suspended = true;
375+
if (asyncMode) {
376+
vnode._suspended = true;
377+
}
377378
throw e;
378379
}
379380
}

test/compat/async.test.jsx

+13-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Async renderToString', () => {
1717
</Suspense>
1818
);
1919

20-
const expected = `<!-- $s --><div class="foo">bar</div><!-- /$s -->`;
20+
const expected = `<!--$s--><div class="foo">bar</div><!--/$s-->`;
2121

2222
suspended.resolve();
2323

@@ -40,7 +40,7 @@ describe('Async renderToString', () => {
4040
</Suspense>
4141
);
4242

43-
const expected = `<!-- $s --><!-- /$s --><div class="foo">bar</div>`;
43+
const expected = `<!--$s--><!--/$s--><div class="foo">bar</div>`;
4444

4545
suspended.resolve();
4646

@@ -73,7 +73,7 @@ describe('Async renderToString', () => {
7373
</ul>
7474
);
7575

76-
const expected = `<ul><!-- $s --><li>one</li><!-- $s --><li>two</li><!-- /$s --><li>three</li><!-- /$s --></ul>`;
76+
const expected = `<ul><!--$s--><li>one</li><!--$s--><li>two</li><!--/$s--><li>three</li><!--/$s--></ul>`;
7777

7878
suspendedOne.resolve();
7979
suspendedTwo.resolve();
@@ -109,7 +109,7 @@ describe('Async renderToString', () => {
109109
</ul>
110110
);
111111

112-
const expected = `<ul><!-- $s --><li>one</li><!-- $s --><li>two</li><!-- /$s --><li>three</li><!-- /$s --></ul>`;
112+
const expected = `<ul><!--$s--><li>one</li><!--$s--><li>two</li><!--/$s--><li>three</li><!--/$s--></ul>`;
113113

114114
suspendedOne.resolve();
115115
suspendedTwo.resolve();
@@ -152,7 +152,7 @@ describe('Async renderToString', () => {
152152
</ul>
153153
);
154154

155-
const expected = `<ul><!-- $s --><li>one</li><!-- $s --><li>two</li><!-- /$s --><!-- $s --><li>three</li><!-- /$s --><li>four</li><!-- /$s --></ul>`;
155+
const expected = `<ul><!--$s--><li>one</li><!--$s--><li>two</li><!--/$s--><!--$s--><li>three</li><!--/$s--><li>four</li><!--/$s--></ul>`;
156156

157157
suspendedOne.resolve();
158158
suspendedTwo.resolve();
@@ -164,7 +164,7 @@ describe('Async renderToString', () => {
164164
expect(rendered).to.equal(expected);
165165
});
166166

167-
it.only('should render JSX with deeply nested suspense boundaries', async () => {
167+
it('should render JSX with deeply nested suspense boundaries', async () => {
168168
const {
169169
Suspender: SuspenderOne,
170170
suspended: suspendedOne
@@ -199,7 +199,7 @@ describe('Async renderToString', () => {
199199
</ul>
200200
);
201201

202-
const expected = `<ul><!-- $s --><li>one</li><!-- $s --><li>two</li><!-- $s --><li>three</li><!-- /$s --><!-- /$s --><li>four</li><!-- /$s --></ul>`;
202+
const expected = `<ul><!--$s--><li>one</li><!--$s--><li>two</li><!--$s--><li>three</li><!--/$s--><!--/$s--><li>four</li><!--/$s--></ul>`;
203203

204204
suspendedOne.resolve();
205205
suspendedTwo.resolve();
@@ -243,7 +243,7 @@ describe('Async renderToString', () => {
243243
</ul>
244244
);
245245

246-
const expected = `<ul><!-- $s --><li>one</li><!-- /$s --><!-- $s --><li>two</li><!-- /$s --><!-- $s --><li>three</li><!-- /$s --></ul>`;
246+
const expected = `<ul><!--$s--><li>one</li><!--/$s--><!--$s--><li>two</li><!--/$s--><!--$s--><li>three</li><!--/$s--></ul>`;
247247

248248
suspendedOne.resolve();
249249
suspendedTwo.resolve();
@@ -303,7 +303,7 @@ describe('Async renderToString', () => {
303303

304304
suspended.resolve();
305305
const rendered = await promise;
306-
expect(rendered).to.equal('<!-- $s --><p>ok</p><!-- /$s -->');
306+
expect(rendered).to.equal('<!--$s--><p>ok</p><!--/$s-->');
307307
});
308308

309309
it('should work with an in-render suspension', async () => {
@@ -340,6 +340,9 @@ describe('Async renderToString', () => {
340340
</Context.Provider>
341341
);
342342

343-
expect(rendered).to.equal(`<div>2</div>`);
343+
// Before we get to the actual DOM this suspends twice
344+
expect(rendered).to.equal(
345+
`<!--$s--><!--$s--><div>2</div><!--/$s--><!--/$s-->`
346+
);
344347
});
345348
});

0 commit comments

Comments
 (0)