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: ["虽然 ", jsx(_components.code, {
        children: "lazy"
      }), " 和 ", jsx(_components.code, {
        children: "createResource"
      }), " 可以单独使用，但 Solid 还提供了一种机制来协调多个异步事件的显示。", jsx(_components.code, {
        children: "Suspense"
      }), " 作为一个边界，可以在这些异步事件未完成时显示回退占位而不是部分加载的内容。"]
    }), "\n", jsxs(_components.p, {
      children: [jsx(_components.code, {
        children: "Suspense"
      }), " 可以通过消除过多的中间和部分加载状态导致的视觉卡顿来改善用户体验。", jsx(_components.code, {
        children: "Suspense"
      }), " 自动侦测所有子级异步读取并相应地采取行动。你可以根据需要嵌套尽可能多的 ", jsx(_components.code, {
        children: "Suspense"
      }), " 组件，并且只有最近的祖先会在检测到加载状态时转换为回退。"]
    }), "\n", jsxs(_components.p, {
      children: ["让我们将 ", jsx(_components.code, {
        children: "Suspense"
      }), " 组件添加到懒加载示例中。"]
    }), "\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: "现在我们有一个加载占位。"
    }), "\n", jsxs(_components.p, {
      children: ["需要注意的是，触发 ", jsx(_components.code, {
        children: "Suspense"
      }), " 的是异步派生值的读取。不是异步获取行为本身。如果在 ", jsx(_components.code, {
        children: "Suspense"
      }), " 边界下未读取资源 Signal（包括 ", jsx(_components.code, {
        children: "lazy"
      }), " 组件），", jsx(_components.code, {
        children: "Suspense"
      }), " 将不会挂起。"]
    }), "\n", jsxs(_components.p, {
      children: [jsx(_components.code, {
        children: "Suspense"
      }), " 在某种意义上来说只是一个渲染两个分支的 ", jsx(_components.code, {
        children: "Show"
      }), " 组件。虽然 ", jsx(_components.code, {
        children: "Suspense"
      }), " 对于异步服务器渲染至关重要，好像没有必要立即将其用于客户端渲染代码的必要。但是 Solid 的细粒度渲染不会给手动拆分逻辑带来额外成本。"]
    }), "\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: "0"
        }), ");\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: "Solid 中的所有工作都已进去独立的队列。不需要像时间切片这样的东西。"
    })]
  });
}
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-607c5ab7.js.map
