Skip to content

Commit 0da840e

Browse files
committed
use shorter notation
1 parent 6017e2d commit 0da840e

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

src/index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const EMPTY_ARR = [];
2929
const isArray = Array.isArray;
3030
const assign = Object.assign;
3131
const EMPTY_STR = '';
32-
const BEGIN_SUSPENSE_DENOMINATOR = '<!-- $s -->';
33-
const END_SUSPENSE_DENOMINATOR = '<!-- /$s -->';
32+
const BEGIN_SUSPENSE_DENOMINATOR = '<!--$s-->';
33+
const END_SUSPENSE_DENOMINATOR = '<!--/$s-->';
3434

3535
// Global state for the current render pass
3636
let beforeDiff, afterDiff, renderHook, ummountHook;
@@ -377,7 +377,9 @@ function _renderToString(
377377
try {
378378
rendered = type.call(component, props, cctx);
379379
} catch (e) {
380-
if (asyncMode) vnode._suspended = true;
380+
if (asyncMode) {
381+
vnode._suspended = true;
382+
}
381383
throw e;
382384
}
383385
}
@@ -541,22 +543,20 @@ function _renderToString(
541543
} catch (e) {
542544
if (!e || typeof e.then != 'function') throw e;
543545

544-
return e.then(
545-
() => {
546-
const result = _renderToString(
547-
rendered,
548-
context,
549-
isSvgMode,
550-
selectValue,
551-
vnode,
552-
asyncMode,
553-
renderer
554-
)
555-
return vnode._suspended
556-
? BEGIN_SUSPENSE_DENOMINATOR + result + END_SUSPENSE_DENOMINATOR
557-
: result;
558-
}, renderNestedChildren
559-
);
546+
return e.then(() => {
547+
const result = _renderToString(
548+
rendered,
549+
context,
550+
isSvgMode,
551+
selectValue,
552+
vnode,
553+
asyncMode,
554+
renderer
555+
);
556+
return vnode._suspended
557+
? BEGIN_SUSPENSE_DENOMINATOR + result + END_SUSPENSE_DENOMINATOR
558+
: result;
559+
}, renderNestedChildren);
560560
}
561561
};
562562

test/compat/async.test.jsx

Lines changed: 13 additions & 10 deletions
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,7 +340,10 @@ 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

346349
describe('dangerouslySetInnerHTML', () => {

0 commit comments

Comments
 (0)