Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove hardcoded require #117

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
> - :house: [Internal]
> - :nail_care: [Polish]

## 0.12.3 [Unreleased]

#### :bug: Bug Fix

- Remove hardcoded `require` so it works in both common js and ES module modes. (https://github.com/rescript-lang/rescript-react/pull/117)

## 0.12.2

- Fix incorrect usage of `@uncurry`.
Expand Down
11 changes: 8 additions & 3 deletions src/RescriptReactErrorBoundary.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/RescriptReactErrorBoundary.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ type params<'error> = {
info: info,
}

type reactComponentClass
@module("react") external component: reactComponentClass = "Component"
let noOp: reactComponentClass => unit = %raw(`function (_x) {}`)
let reactComponentClass = component
// this is so that the compiler doesn't optimize away the previous line
noOp(reactComponentClass)

%%raw(`
var React = require("react");

var ErrorBoundary = (function (Component) {
function ErrorBoundary(props) {
Expand All @@ -28,7 +34,7 @@ var ErrorBoundary = (function (Component) {
: this.props.children;
};
return ErrorBoundary;
})(React.Component);
})(reactComponentClass);
`)

@react.component @val
Expand Down
Loading