import { jsx, jsxs, Fragment } from 'solid-jsx/jsx-runtime';

/*@jsxRuntime automatic @jsxImportSource solid-jsx*/
const toc = [];
function _createMdxContent(props) {
  const _components = Object.assign({
    p: "p",
    code: "code",
    pre: "pre",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsxs(_components.p, {
      children: ["While ", jsx(_components.code, {
        children: "lazy"
      }), " and ", jsx(_components.code, {
        children: "createResource"
      }), " can be used on their own, Solid also provides a mechanism for coordinating the display of multiple async events. ", jsx(_components.code, {
        children: "Suspense"
      }), " serves as a boundary that can show a fallback placeholder instead of the partially loaded content as these async events resolve."]
    }), "\n", jsxs(_components.p, {
      children: ["This can improve user experience by removing visual jank caused by too many intermediate and partial loading states. ", jsx(_components.code, {
        children: "Suspense"
      }), " automatically detects any descendant async reads and acts accordingly. You can nest as many ", jsx(_components.code, {
        children: "Suspense"
      }), " components as needed and only the nearest ancestor will transform to ", jsx(_components.code, {
        children: "fallback"
      }), " when the ", jsx(_components.code, {
        children: "loading"
      }), " state is detected."]
    }), "\n", jsxs(_components.p, {
      children: ["Let's add a ", jsx(_components.code, {
        children: "Suspense"
      }), " component to our lazy loading example:"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: ["<>\n  ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "h1"
            }), ">"]
          }), "Welcome", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "h1"
            }), ">"]
          })]
        }), "\n  ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "Suspense"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "fallback"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "{"
            }), "<", jsx(_components.span, {
              className: "hljs-attr",
              children: "p"
            }), ">"]
          }), "Loading...", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "p"
            }), ">"]
          }), "}>\n    ", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "Greeting"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "name"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "\"Jake\""
            }), " />"]
          }), "\n  ", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "Suspense"
            }), ">"]
          })]
        }), "\n</>\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "Now we have a loading placeholder."
    }), "\n", jsxs(_components.p, {
      children: ["It's important to note that it's the read of an async derived value that triggers ", jsx(_components.code, {
        children: "Suspense"
      }), ", not the async fetching itself. If a resource signal (including ", jsx(_components.code, {
        children: "lazy"
      }), " components) is not read under the ", jsx(_components.code, {
        children: "Suspense"
      }), " boundary, it will not suspend."]
    }), "\n", jsxs(_components.p, {
      children: [jsx(_components.code, {
        children: "Suspense"
      }), " in many ways is just a ", jsx(_components.code, {
        children: "Show"
      }), " component that renders both branches. While ", jsx(_components.code, {
        children: "Suspense"
      }), " is vital for asynchronous Server rendering, do not feel the need to jump immediately to using it for client-rendered code. Solid's fine-grained rendering has no additional cost for splitting things manually."]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "function"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "Deferred"
        }), "(", jsx(_components.span, {
          className: "hljs-params",
          children: "props"
        }), ") {\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " [resume, setResume] = ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "createSignal"
        }), "(", jsx(_components.span, {
          className: "hljs-literal",
          children: "false"
        }), ");\n  ", jsx(_components.span, {
          className: "hljs-built_in",
          children: "setTimeout"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setResume"
        }), "(", jsx(_components.span, {
          className: "hljs-literal",
          children: "true"
        }), "), ", jsx(_components.span, {
          className: "hljs-number",
          children: "1000"
        }), ");\n\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "return"
        }), " ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "Show"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "when"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "{resume()}"
            }), ">"]
          }), "{props.children}", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "Show"
            }), ">"]
          })]
        }), ";\n}\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "All work in Solid is queued independently already. No need for things like Time Slicing."
    })]
  });
}
function MDXContent(props = {}) {
  const {wrapper: MDXLayout} = props.components || ({});
  return MDXLayout ? jsx(MDXLayout, Object.assign({}, props, {
    children: jsx(_createMdxContent, props)
  })) : _createMdxContent(props);
}

export { MDXContent as default, toc };
//# sourceMappingURL=lesson-e8a301bb.js.map
