mono-jsx 0.8.1 → 0.8.2

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/README.md CHANGED
@@ -344,7 +344,7 @@ async function Loader(props: { url: string }) {
344
344
  export default {
345
345
  fetch: (req) => (
346
346
  <html>
347
- <Loader url="https://api.example.com/data" placeholder={<p>Loading...</p>} />
347
+ <Loader url="https://api.example.com/data" pending={<p>Loading...</p>} />
348
348
  </html>
349
349
  )
350
350
  }
@@ -371,13 +371,13 @@ async function* Chat(props: { prompt: string }) {
371
371
  export default {
372
372
  fetch: (req) => (
373
373
  <html>
374
- <Chat prompt="Tell me a story" placeholder={<span style="color:grey">●</span>} />
374
+ <Chat prompt="Tell me a story" pending={<span style="color:grey">●</span>} />
375
375
  </html>
376
376
  )
377
377
  }
378
378
  ```
379
379
 
380
- You can use `placeholder` to display a loading state while waiting for async components to render:
380
+ You can use `pending` to display a loading state while waiting for async components to render:
381
381
 
382
382
  ```tsx
383
383
  async function Sleep({ ms }) {
@@ -388,7 +388,7 @@ async function Sleep({ ms }) {
388
388
  export default {
389
389
  fetch: (req) => (
390
390
  <html>
391
- <Sleep ms={1000} placeholder={<p>Loading...</p>}>
391
+ <Sleep ms={1000} pending={<p>Loading...</p>}>
392
392
  <p>After 1 second</p>
393
393
  </Sleep>
394
394
  </html>
@@ -396,7 +396,7 @@ export default {
396
396
  }
397
397
  ```
398
398
 
399
- You can set the `rendering` attribute to `"eager"` to force synchronous rendering (the `placeholder` will be ignored):
399
+ You can set the `rendering` attribute to `"eager"` to force synchronous rendering (the `pending` property will be ignored):
400
400
 
401
401
  ```tsx
402
402
  export default {
@@ -441,7 +441,7 @@ function Foo(props: { bar: string }) {
441
441
  export default {
442
442
  fetch: (req) => (
443
443
  <html request={req} components={{ Foo }}>
444
- <component name="Foo" props={{ bar: "baz" }} placeholder={<p>Loading...</p>} />
444
+ <component name="Foo" props={{ bar: "baz" }} pending={<p>Loading...</p>} />
445
445
  </html>
446
446
  )
447
447
  }
@@ -453,7 +453,7 @@ You can use the `<component>` element with the `is` prop to render a component b
453
453
  export default {
454
454
  fetch: (req) => (
455
455
  <html request={req}>
456
- <component is={Foo} props={{ bar: "baz" }} placeholder={<p>Loading...</p>} />
456
+ <component is={Foo} props={{ bar: "baz" }} pending={<p>Loading...</p>} />
457
457
  </html>
458
458
  )
459
459
  }
@@ -465,7 +465,7 @@ Or you can use the `<component>` element with the `as` prop to render a componen
465
465
  export default {
466
466
  fetch: (req) => (
467
467
  <html request={req}>
468
- <component as={<Foo bar="baz" />} placeholder={<p>Loading...</p>} />
468
+ <component as={<Foo bar="baz" />} pending={<p>Loading...</p>} />
469
469
  </html>
470
470
  )
471
471
  }
@@ -487,7 +487,7 @@ function Dash(this: FC<{ page: "Profile" | "Projects" | "Settings" }>) {
487
487
  <button onClick={() => this.page = "Settings"}>Settings</button>
488
488
  </div>
489
489
  <div class="page">
490
- <component name={this.page} placeholder={<p>Loading...</p>} />
490
+ <component name={this.page} pending={<p>Loading...</p>} />
491
491
  </div>
492
492
  </>
493
493
  )
@@ -509,7 +509,7 @@ async function Lazy(this: FC<{ show: boolean }>, props: { url: string }) {
509
509
  return (
510
510
  <div>
511
511
  <show when={this.show}>
512
- <component name="Foo" props={{ bar: "baz" }} placeholder={<p>Loading...</p>} />
512
+ <component name="Foo" props={{ bar: "baz" }} pending={<p>Loading...</p>} />
513
513
  </show>
514
514
  <button onClick={() => this.show = true }>Load `Foo` Component</button>
515
515
  </div>
@@ -543,28 +543,28 @@ var renderFC = (fc, props, root, abortSignal) => {
543
543
  call$expr(scope, true);
544
544
  v = fc.call(scope, props);
545
545
  if (v instanceof Promise) {
546
- let placeholder;
547
- if (isVNode(props.placeholder)) {
548
- placeholder = [...renderToFragment(scope, props.placeholder, abortSignal).childNodes];
546
+ let pendingNodes;
547
+ if (isVNode(props.pending)) {
548
+ pendingNodes = [...renderToFragment(scope, props.pending, abortSignal).childNodes];
549
549
  }
550
- if (!placeholder?.length) {
551
- placeholder = [createTextNode()];
550
+ if (!pendingNodes?.length) {
551
+ pendingNodes = [createTextNode()];
552
552
  }
553
- root.append(...placeholder);
553
+ root.append(...pendingNodes);
554
554
  v.then((nodes) => {
555
555
  call$expr(scope, false);
556
- placeholder[0].replaceWith(...renderToFragment(scope, nodes, abortSignal).childNodes);
556
+ pendingNodes[0].replaceWith(...renderToFragment(scope, nodes, abortSignal).childNodes);
557
557
  }).catch((err) => {
558
558
  if (isFunction(props.catch)) {
559
559
  const v2 = props.catch(err);
560
560
  if (isVNode(v2)) {
561
- placeholder[0].replaceWith(...renderToFragment(scope, v2, abortSignal).childNodes);
561
+ pendingNodes[0].replaceWith(...renderToFragment(scope, v2, abortSignal).childNodes);
562
562
  }
563
563
  } else {
564
564
  console.error(err);
565
565
  }
566
566
  }).finally(() => {
567
- placeholder.forEach((node) => node.remove());
567
+ pendingNodes.forEach((node) => node.remove());
568
568
  });
569
569
  } else {
570
570
  call$expr(scope, false);
package/jsx-runtime.mjs CHANGED
@@ -681,7 +681,7 @@ async function renderNode(rc, node, stripSlotProp) {
681
681
  }
682
682
  // `<component>` element
683
683
  case "component": {
684
- let { placeholder, is, as } = props;
684
+ let { pending, is, as } = props;
685
685
  let attrs = "";
686
686
  let attrModifiers = "";
687
687
  let writeAttr = (propName, propValue = props[propName]) => {
@@ -710,11 +710,11 @@ async function renderNode(rc, node, stripSlotProp) {
710
710
  writeAttr("ref");
711
711
  attrs += renderViewTransitionAttr(props);
712
712
  let buf = "<m-component" + attrs + ">";
713
- if (placeholder) {
713
+ if (pending) {
714
714
  const write2 = (chunk) => {
715
715
  buf += chunk;
716
716
  };
717
- await renderChildren({ ...rc, write: write2 }, placeholder);
717
+ await renderChildren({ ...rc, write: write2 }, pending);
718
718
  }
719
719
  buf += "</m-component>";
720
720
  if (attrModifiers) {
@@ -927,8 +927,8 @@ async function renderFC(rc, fcFn, props, eager) {
927
927
  } else {
928
928
  const chunkIdAttr = 'chunk-id="' + (rc.flags.chunk++).toString(36) + '"';
929
929
  write("<m-portal " + chunkIdAttr + ">");
930
- if (props.placeholder) {
931
- await renderNode(rc, props.placeholder);
930
+ if (props.pending) {
931
+ await renderNode(rc, props.pending);
932
932
  }
933
933
  write("</m-portal>");
934
934
  rc.suspenses.push(v.then(async (node) => {
@@ -951,8 +951,8 @@ async function renderFC(rc, fcFn, props, eager) {
951
951
  } else {
952
952
  const chunkIdAttr = 'chunk-id="' + (rc.flags.chunk++).toString(36) + '"';
953
953
  write("<m-portal " + chunkIdAttr + ">");
954
- if (props.placeholder) {
955
- await renderNode(rc, props.placeholder);
954
+ if (props.pending) {
955
+ await renderNode(rc, props.pending);
956
956
  }
957
957
  write("</m-portal>");
958
958
  const iter = () => rc.suspenses.push(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mono-jsx",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "`<html>` as a `Response`.",
5
5
  "type": "module",
6
6
  "module": "./index.mjs",
package/types/jsx.d.ts CHANGED
@@ -38,7 +38,7 @@ export interface AsyncComponentAttributes {
38
38
  /**
39
39
  * The loading spinner for an async component.
40
40
  */
41
- placeholder?: JSX.Element;
41
+ pending?: JSX.Element;
42
42
  /**
43
43
  * Rendering mode of an async component.
44
44
  * - `eager`: render async components eagerly