{"id":29926572,"url":"https://github.com/ecomfe/react-suspense-boundary","last_synced_at":"2025-10-08T12:39:38.082Z","repository":{"id":37444403,"uuid":"197732320","full_name":"ecomfe/react-suspense-boundary","owner":"ecomfe","description":"A boundary component working with suspense and error","archived":false,"fork":false,"pushed_at":"2024-03-22T12:34:36.000Z","size":8295,"stargazers_count":84,"open_issues_count":9,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-03T03:03:58.485Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecomfe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-07-19T08:17:44.000Z","updated_at":"2024-03-20T05:44:30.000Z","dependencies_parsed_at":"2024-03-22T04:30:59.985Z","dependency_job_id":"6499a22d-ed72-42f5-b59e-95feaf48113c","html_url":"https://github.com/ecomfe/react-suspense-boundary","commit_stats":{"total_commits":110,"total_committers":4,"mean_commits":27.5,"dds":"0.027272727272727226","last_synced_commit":"b8b4fa3b848ee247f507afba06dae9560b534e9b"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/ecomfe/react-suspense-boundary","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Freact-suspense-boundary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Freact-suspense-boundary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Freact-suspense-boundary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Freact-suspense-boundary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomfe","download_url":"https://codeload.github.com/ecomfe/react-suspense-boundary/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Freact-suspense-boundary/sbom","scorecard":{"id":365658,"data":{"date":"2025-08-11","repo":{"name":"github.com/ecomfe/react-suspense-boundary","commit":"e923b628310aa5f991f882895332df2159677aff"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 2/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"43 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-8hc4-vh64-cxmj","Warn: Project is vulnerable to: GHSA-jr5f-v2jv-69x6","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6","Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27","Warn: Project is vulnerable to: GHSA-4www-5p9h-95mh","Warn: Project is vulnerable to: GHSA-9gqv-wp59-fq42","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-x7hr-w5r2-h6wg","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-3f95-r44v-8mrg","Warn: Project is vulnerable to: GHSA-28xr-mwxg-3qc8","Warn: Project is vulnerable to: GHSA-9p95-fxvg-qgq2","Warn: Project is vulnerable to: GHSA-9w5j-4mwv-2wj8","Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g","Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3","Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx","Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6","Warn: Project is vulnerable to: GHSA-x574-m823-4x7w","Warn: Project is vulnerable to: GHSA-4r4m-qw57-chr8","Warn: Project is vulnerable to: GHSA-xcj6-pq6g-qj4x","Warn: Project is vulnerable to: GHSA-356w-63v5-8wf4","Warn: Project is vulnerable to: GHSA-859w-5945-r5v3","Warn: Project is vulnerable to: GHSA-9crc-q9x8-hgqq","Warn: Project is vulnerable to: GHSA-4v9v-hfq4-rm2v","Warn: Project is vulnerable to: GHSA-9jgg-88mc-972h","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T11:47:21.658Z","repository_id":37444403,"created_at":"2025-08-18T11:47:21.658Z","updated_at":"2025-08-18T11:47:21.658Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278947368,"owners_count":26073725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-02T12:42:04.656Z","updated_at":"2025-10-08T12:39:38.044Z","avatar_url":"https://github.com/ecomfe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-suspense-boundary\n\nA boundary component working with suspense and error\n\nVersion 2.x is implemented on [use-sync-external-store](https://www.npmjs.com/package/use-sync-external-store) to align with future official suspense data fetching.\n\n## Install\n\n```shell\nnpm install react-suspense-boundary\n```\n\n## Demo\n\nSee online demo here: [https://ecomfe.github.io/react-suspense-boundary/](https://ecomfe.github.io/react-suspense-boundary/)\n\nYou can start demo app yourself by executing:\n\n```shell\nnpm start\n```\n\n## Usage\n\n### Basic\n\n```jsx\nimport {Boundary, CacheProvider, useResource} from 'react-suspense-boundary';\n\n// Create or import an async function\nconst fetchInfo = ({id}) =\u003e fetch(`/info/${id}`).then(response =\u003e response.json());\n\n// Implement your presentational component\nfunction Info({id}) {\n    // Call `useResource` to fetch, note the return value is an array\n    const [info] = useResource(fetchInfo, {id});\n\n    // There is no `loading` branch, push returned object immediately to render\n    return (\n        \u003cdiv\u003e\n            {info.id}: {info.name}\n        \u003c/div\u003e\n    );\n};\n\n// Data is stored inside `CacheProvider`, suspending state is controlled with `Boundary`\nexport default function App() =\u003e (\n    \u003cCacheProvider\u003e\n        \u003cBoundary\u003e\n            \u003cInfo /\u003e\n        \u003c/Boundary\u003e\n    \u003c/CacheProvider\u003e\n);\n```\n\n### CacheProvider\n\n`CacheProvider` is by its name a cache context where we store all resources loaded by its children.\n\nThe simpliest way to use `CacheProvider` is to provider an application level top cache:\n\n```tsx\nimport {render} from 'react-dom';\nimport {CacheProvider} from 'react-suspense-boundary';\nimport {App} from './components/App';\n\nrender(\n    \u003cCacheProvider\u003e\n        \u003cApp /\u003e\n    \u003c/CacheProvider\u003e,\n    document.getElementById('root')\n);\n```\n\nFor some more complex applications, you may want to restrict data caching in a smaller scope, e.g. route level, and expire cached responses on unmount, you can put `CacheProvider` anywhere you want to make a shared cache.\n\n### Boundary\n\n`Boundary` components defines a boundary in your view, within a boundary all async resource fetchings and errors are collected to form a loading or error indicator.\n\nUsually we would have mulitple `Boundary` inside a `CacheProvider`, that is, users see different sections loading individually, but all resources are shared.\n\nA `Boundary` component receives props below:\n\n```typescript\ninterface RenderErrorOptions {\n    recover: () =\u003e void;\n}\n\ninterface BoundaryProps {\n    // When any of async progress is pending, boundary will render this element\n    pendingFallback: ReactNode;\n    // When any error are received, will render this function\n    renderError(error: Error, options: RenderErrorOptions): ReactNode;\n    // When any error are catched, will call this function\n    onErrorCaught(error: Error, info: ErrorInfo): void;\n}\n```\n\n### useResource\n\nThe `useResource` hook is used to inspect an async function within a boundary:\n\n```ts\ntype Resource\u003cT\u003e = [\n    T,\n    {\n        expire(): void;\n        refresh(): void;\n    }\n];\n\nfunction useResource\u003cI, O\u003e(action: (input: I) =\u003e Promise\u003cO\u003e, params: I): Resource\u003cO\u003e;\nfunction useConstantResource\u003cO\u003e(action: () =\u003e Promise\u003cO\u003e): Resource\u003cO\u003e;\n```\n\nUnlike other async hooks, `useResource` returns the result \"immediately\", there is no `pending` or `loading` state, no exception will throw.\n\nOther than the result itself, the second object of `useResource`'s returned array is a a bunch of functions to manually control the cache:\n\n- `expire` will immediately remove the cached result, causing the upper `Boundary` to be pending until `action` is resolved the next time.\n- `refresh` is a function to run `action` again without removing previously cached result.\n\n### Default configuration\n\n`BoundaryConfigProvider` provides default configurations to `pendingFallback`, `renderError` and `onErrorCaught` props.\n\n```javascript\nimport {Spin} from 'antd';\nimport {BoundaryConfigProvider} from 'react-suspense-boundary';\n\nconst defaultPendingFallback = \u003cSpin /\u003e;\n\nconst defaultRenderError = error =\u003e (\n    \u003cdiv\u003e\n        {error.message}\n    \u003c/div\u003e\n);\n\nconst App = () =\u003e {\n    \u003cBoundaryConfigProvider\n        pendingFallback={defaultPendingFallback}\n        renderError={defaultRenderError}\n    \u003e\n        {/* All Boundary elements inside it receives default configurations */}\n    \u003c/BoundaryConfigProvider\u003e\n}\n```\n\n### Preload\n\nPreload is much like resource fetching, they can be \"immediately\" fired within a render function:\n\n```ts\nfunction usePreloadResource\u003cI, O\u003e(action: (input: I) =\u003e Promise\u003cO\u003e, params: I): void;\nfunction usePreloadConstantResource\u003cO\u003e(action: () =\u003e Promise\u003cO\u003e): void;\n```\n\nPreload fires resource fetching process but not abort current render.\n\nYou can also get a `preload` function using `usePreloadCallback` hook to preload any resources in effect or event handlers:\n\n```tsx\nconst preload = usePreloadCallback();\n\n\u003cButton onMouseEnter={() =\u003e preload(fetchList, {pageIndex: currentPageIndex + 1})}\u003e\n    Next Page\n\u003c/Button\u003e\n```\n\n## Create Your Own Cache\n\n`react-suspense-boundary`'s built-in `CacheProvider` references a single context type, that is, you are unable to access multiple caches in a single component:\n\n```tsx\n\u003cCacheProvider\u003e\n    \u003cdiv\u003e\n        \u003cCacheProvider\u003e\n            \u003cMyResource /\u003e\n        \u003c/CacheProvider\u003e\n    \u003c/div\u003e\n\u003c/CacheProvider\u003e\n```\n\nBy default, there is no way to a make `MyResource` to load one resource into the outer `CacheProvider` and another into the inner `CacheProvider`.\n\nTo solve this issue, we provide a `create()` function to create a custom set of providers and hooks, with a different context type so that you can use them simultaneously:\n\n```tsx\nimport {CacheProvider, create, useConstantResource} from 'react-suspense-boundary';\n\nconst {\n    CacheProvider: GlobalCacheProvider,\n    useConstantResource: useGlobalConstantResource,\n} = create();\n\nfunction MyResource() {\n    // Put current user resource into global cache\n    const [currentUser] = useGlobalConstantResource(fetchCurrentUser);\n    // And other resources into local one\n    const [dataSource] = useConstantResource(fetchList);\n\n    return (\n        // ...\n    );\n}\n\n\u003cGlobalCacheProvider\u003e\n    \u003cCacheProvider\u003e\n        \u003cMyResource /\u003e\n    \u003c/CacheProvider\u003e\n\u003c/GlobalCacheProvider\u003e\n```\n\n`create` function also accepts an option object to customize context's display name:\n\n```ts\ninterface CreateOptions {\n    cacheContextDisplayName?: string;\n    configContextDisplayName?: string;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Freact-suspense-boundary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomfe%2Freact-suspense-boundary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Freact-suspense-boundary/lists"}