Skip to content
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: 3 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@master

- name: Setup Node.js 22.x
uses: actions/setup-node@master
- name: Setup Node.js 24
uses: actions/setup-node@v6
with:
node-version: 22.x
node-version: 24

- name: Install Dependencies
run: yarn --frozen-lockfile --ignore-scripts
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 22.x
uses: actions/setup-node@master
- name: Setup Node.js 24
uses: actions/setup-node@v6
with:
node-version: 22.x
node-version: 24

- name: Install Dependencies
run: yarn --frozen-lockfile --ignore-scripts
Expand Down
25 changes: 16 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

permissions:
contents: write
id-token: write
pull-requests: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@main
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 22.x
uses: actions/setup-node@master
- name: Setup Node.js 24
uses: actions/setup-node@v6
with:
node-version: 22.x
node-version: 24
registry-url: https://registry.npmjs.org

- name: Install Dependencies
run: yarn
Expand All @@ -29,12 +38,10 @@ jobs:

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
uses: changesets/action@v1.7.0
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
commit: Version release
title: Next release
publish: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

29 changes: 29 additions & 0 deletions docs/react-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,35 @@ Now you can see component names:

</details>

<details id="eslint-hooks"><summary>**Tip:** `eslint-plugin-react-hooks` compatibility with `observer`<a href="#eslint-hooks" class="tip-anchor"></a>
</summary>

By default, [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks) rules (such as `rules-of-hooks` and `exhaustive-deps`) only recognize components defined as named functions or arrow functions directly assigned to a variable. When you write:

```javascript
// Arrow function — ESLint react-hooks rules will NOT check this component
const MyComponent = observer(props => { ... })
```

ESLint cannot tell that `observer`'s return value is a component, so the hooks rules are silently skipped.

The fix is the same as the one for React DevTools display names: **use a named function inside `observer`**:

```javascript
// Named function — ESLint react-hooks rules WILL check this component ✓
const MyComponent = observer(function MyComponent(props) {
// hooks are now validated by eslint-plugin-react-hooks
const [value, setValue] = React.useState(0)
return <div>{value}</div>
})
```

This pattern also provides accurate names in React DevTools and stack traces. It is the recommended way to define observable components.

If you prefer arrow functions, you can configure [`eslint-plugin-react`](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-) with the `componentWrapperFunctions` setting to teach ESLint about `observer`, but note that this only affects `eslint-plugin-react` rules, not `eslint-plugin-react-hooks`.

</details>

<details id="wrap-order"><summary>{🚀} **Tip:** when combining `observer` with other higher-order-components, apply `observer` first<a href="#wrap-order" class="tip-anchor"></a></summary>

When `observer` needs to be combined with other decorators or higher-order-components, make sure that `observer` is the innermost (first applied) decorator;
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn",
"npmClient": "npm",
"useWorkspaces": true
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
},
"repository": {
"type": "git",
"url": "https://github.com/mobxjs/mobx.git"
"url": "git+https://github.com/mobxjs/mobx.git"
},
"scripts": {
"test": "jest",
"coverage": "jest --coverage",
"lint": "eslint packages/*/src/**/* --ext .js,.ts,.tsx",
"prettier": "prettier --write **/*.{js,ts,md}",
"release": "yarn lerna run prepublishOnly && yarn changeset publish",
"release": "lerna run prepublishOnly && changeset publish",
"mobx": "yarn workspace mobx",
"mobx-react": "yarn workspace mobx-react",
"mobx-react-lite": "yarn workspace mobx-react-lite",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-mobx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"test:7": "jest --config jest.config-eslint-7.js",
"test:9": "jest --config jest.config-eslint-9.js",
"test": "npm run test:7 && npm run test:9",
"build": "yarn rollup --config",
"prepublishOnly": "yarn build"
"build": "rollup --config",
"prepublishOnly": "npm run build"
}
}
8 changes: 4 additions & 4 deletions packages/mobx-react-lite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
"scripts": {
"lint": "eslint src/**/* --ext .js,.ts,.tsx",
"build": "node ../../scripts/build.js mobxReactLite",
"build:test": "yarn build --target test",
"build:test": "npm run build --target test",
"build:cjs": "tsc --project tsconfig.build.cjs.json",
"build:es": "tsc --project tsconfig.build.es.json",
"test": "jest",
"test:size": "yarn import-size --report . observer useLocalObservable",
"test:size": "import-size --report . observer useLocalObservable",
"test:types": "tsc --noEmit",
"test:check": "yarn test:types",
"prepublishOnly": "cd ../mobx && yarn build --target publish && cd ../mobx-react-lite && yarn build --target publish && yarn build:cjs && yarn build:es"
"test:check": "npm run test:types",
"prepublishOnly": "cd ../mobx && npm run build --target publish && cd ../mobx-react-lite && npm run build --target publish && npm run build:cjs && npm run build:es"
}
}
8 changes: 4 additions & 4 deletions packages/mobx-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
"scripts": {
"lint": "eslint src/**/* --ext .js,.ts,.tsx",
"build": "node ../../scripts/build.js mobxReact",
"build:test": "yarn build --target test",
"build:test": "npm run build --target test",
"test": "jest",
"test:size": "yarn import-size --report . observer",
"test:size": "npm run import-size --report . observer",
"test:types": "tsc --noEmit",
"test:check": "yarn test:types",
"prepublishOnly": "yarn build --target publish"
"test:check": "npm run test:types",
"prepublishOnly": "npm run build --target publish"
}
}
6 changes: 3 additions & 3 deletions packages/mobx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/mobxjs/mobx.git"
"url": "git+https://github.com/mobxjs/mobx.git"
},
"author": "Michel Weststrate",
"license": "MIT",
Expand Down Expand Up @@ -64,7 +64,7 @@
"test": "jest --config jest.projects.js",
"lint": "eslint src/**/*",
"build": "node ../../scripts/build.js mobx",
"build:test": "yarn build --target test",
"build:test": "npm run build --target test",
"perf": "scripts/perf.sh",
"perf-legacy": "node --expose-gc ./__tests__/perf/index.js legacy",
"perf-proxy": "node --expose-gc ./__tests__/perf/index.js proxy",
Expand All @@ -75,6 +75,6 @@
"test:coverage": "yarn test -i --coverage",
"test:size": "yarn import-size --report . observable computed autorun action",
"test:check": "yarn test:types",
"prepublishOnly": "node ./scripts/prepublish.js && yarn build --target publish"
"prepublishOnly": "node ./scripts/prepublish.js && npm run build --target publish"
}
}
Loading
Loading