{"id":22165278,"url":"https://github.com/doochik/babel-plugin-transform-react-ssr-try-catch","last_synced_at":"2025-07-26T11:31:59.172Z","repository":{"id":26703452,"uuid":"108421262","full_name":"doochik/babel-plugin-transform-react-ssr-try-catch","owner":"doochik","description":"Wraps render() method in React.Component with try-catch statement","archived":false,"fork":false,"pushed_at":"2024-04-23T18:08:58.000Z","size":233,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-24T19:08:41.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/doochik.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2017-10-26T14:17:29.000Z","updated_at":"2024-06-20T23:26:21.279Z","dependencies_parsed_at":"2024-06-20T23:26:14.300Z","dependency_job_id":"02572d8f-ecf9-4da6-8c45-7fdec1cfbacc","html_url":"https://github.com/doochik/babel-plugin-transform-react-ssr-try-catch","commit_stats":{"total_commits":43,"total_committers":4,"mean_commits":10.75,"dds":"0.39534883720930236","last_synced_commit":"25e347c4da85478c17e5166a2a0f1c0da0851d0c"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doochik%2Fbabel-plugin-transform-react-ssr-try-catch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doochik%2Fbabel-plugin-transform-react-ssr-try-catch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doochik%2Fbabel-plugin-transform-react-ssr-try-catch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doochik%2Fbabel-plugin-transform-react-ssr-try-catch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doochik","download_url":"https://codeload.github.com/doochik/babel-plugin-transform-react-ssr-try-catch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227673984,"owners_count":17802303,"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","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":"2024-12-02T05:14:20.697Z","updated_at":"2024-12-02T05:14:21.200Z","avatar_url":"https://github.com/doochik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @doochik/babel-plugin-transform-react-ssr-try-catch\n\nBabel plugin to wrap render() method in React.Component with try-catch statement.\n\n## Motivation\n\nReact 16 has [error handling](https://reactjs.org/blog/2017/09/26/react-v16.0.html#better-error-handling) but for [client rendering only](https://github.com/facebook/react/issues/10442). \n\nThis plugin performs simple transform which wraps every render() method with try-catch.\nExample:\n```js\n// MyComponent.js\n\nclass MyCompoenent extends React.PureComponent {\n  render() {\n    return \u003cdiv/\u003e;\n  }\n}\n```\n\nThis component will be transofmed to:\n```js\n// MyComponent.js\nconst ReactSSRErrorHandler = require('./path/to/my/SSRErrorHandler.js');\n\nclass MyCompoenent extends React.PureComponent {\n  render() {\n      try {\n          return this.__originalRenderMethod__();\n      } catch (e) {\n          return ReactSSRErrorHandler(e, this.constructor.name, this);\n      }\n  }\n\n  __originalRenderMethod__() {\n      return \u003cdiv /\u003e;\n  }\n}\n```\n\nActually, this is temporary solution until React doesn't support error handling in SSR.\n\n## Installation\n\n```sh\nnpm install --save-dev @doochik/babel-plugin-transform-react-ssr-try-catch\n```\n\n## Usage\n\n**You should enable this plugin only for server build. Use React 16 error boundaries from client build.**\n\n**.babelrc**\n\n```json\n{\n    \"plugins\": [\n        [\"react-ssr-try-catch\", {\n            // global errorHandler\n            \"errorHandler\": \"./path/to/my/SSRErrorHandler.js\",\n            // component error render method\n            \"errorRenderMethod\": \"renderErrorState\",\n            \"type\": \"module\"\n        }]\n    ]\n}\n```\n\n## Options\n\n### `type`\n\nTo generate ESM imports add option `type='module'`\n\n\n### `errorHandler`\n\nPath to your errorHandler module.\nThis is simple function with three arguments `(error, componentName, componentContext)`\n\n```js\n// SSRErrorHandler.js\n\nmodule.exports = (error, componentName, componentContext) =\u003e {\n   // here you can log error and return fallback component or null.\n}\n```\n\n### `errorRenderMethod`\n\nComponent method name to render error state\nMethod invokes with two arguments `(error, componentName)`\n\n```js\n// original component\n\nclass TestComponent extends React.PureComponent {\n    render() {\n        return \u003cdiv/\u003e;\n    }\n\n    renderErrorState() {\n        return \u003cp\u003eoops!\u003c/p\u003e;\n    }\n}\n\n// component after transformation\nclass TestComponent extends React.PureComponent {\n    render() {\n        try {\n            return this.__originalRenderMethod__();\n        } catch (e) {\n            return this.renderErrorState(e, this.constructor.name);\n        }\n    }\n\n    renderErrorState() {\n        return \u003cp\u003eoops!\u003c/p\u003e;\n    }\n\n    __originalRenderMethod__() {\n        return \u003cdiv /\u003e;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoochik%2Fbabel-plugin-transform-react-ssr-try-catch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoochik%2Fbabel-plugin-transform-react-ssr-try-catch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoochik%2Fbabel-plugin-transform-react-ssr-try-catch/lists"}