Skip to content

Commit

Permalink
use shorter notation
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jul 19, 2024
1 parent 63015ed commit 28872c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import {
} from './lib/constants.js';

const EMPTY_ARR = [];
const EMPTY_OBJ = {};
const isArray = Array.isArray;
const assign = Object.assign;
const BEGIN_SUSPENSE_DENOMINATOR = '<!--$s-->';
const END_SUSPENSE_DENOMINATOR = '<!--/$s-->';

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

const EMPTY_OBJ = {};
const BEGIN_SUSPENSE_DENOMINATOR = '<!-- $s -->';
const END_SUSPENSE_DENOMINATOR = '<!-- /$s -->';

/**
* @param {VNode} vnode
* @param {Record<string, unknown>} context
Expand Down Expand Up @@ -373,7 +372,9 @@ function _renderToString(
try {
rendered = type.call(component, props, cctx);
} catch (e) {
if (asyncMode) vnode._suspended = true;
if (asyncMode) {
vnode._suspended = true;
}
throw e;
}
}
Expand Down
23 changes: 13 additions & 10 deletions test/compat/async.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Async renderToString', () => {
</Suspense>
);

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

suspended.resolve();

Expand All @@ -40,7 +40,7 @@ describe('Async renderToString', () => {
</Suspense>
);

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

suspended.resolve();

Expand Down Expand Up @@ -73,7 +73,7 @@ describe('Async renderToString', () => {
</ul>
);

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

suspendedOne.resolve();
suspendedTwo.resolve();
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('Async renderToString', () => {
</ul>
);

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

suspendedOne.resolve();
suspendedTwo.resolve();
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('Async renderToString', () => {
</ul>
);

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

suspendedOne.resolve();
suspendedTwo.resolve();
Expand All @@ -164,7 +164,7 @@ describe('Async renderToString', () => {
expect(rendered).to.equal(expected);
});

it.only('should render JSX with deeply nested suspense boundaries', async () => {
it('should render JSX with deeply nested suspense boundaries', async () => {
const {
Suspender: SuspenderOne,
suspended: suspendedOne
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Async renderToString', () => {
</ul>
);

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

suspendedOne.resolve();
suspendedTwo.resolve();
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('Async renderToString', () => {
</ul>
);

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

suspendedOne.resolve();
suspendedTwo.resolve();
Expand Down Expand Up @@ -303,7 +303,7 @@ describe('Async renderToString', () => {

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

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

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

0 comments on commit 28872c3

Please sign in to comment.