Skip to content

Commit b97fbaa

Browse files
authored
fix: callback ref cleanup compatibility across React 17–19 (#760)
* test: cover packed React compatibility * fix: gate callback ref cleanup by React version * fix: parse React ref cleanup support conservatively * test: compose callback refs across React versions * test: simplify packed React compatibility * test: run packed harness as native TypeScript
1 parent 9cd27bd commit b97fbaa

9 files changed

Lines changed: 484 additions & 9 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ jobs:
6060
run: pnpm add -D react@${{ matrix.react }} react-dom@${{ matrix.react }}
6161
- name: Validate types
6262
run: pnpm tsc
63+
- name: Build package
64+
run: pnpm build
65+
- name: Test packed package
66+
if: ${{ matrix.react != 'latest' }}
67+
run: pnpm run compat:packed -- ${{ matrix.react }}
6368
- name: Run test
6469
run: |
6570
pnpm exec playwright install

‎fixtures/react-compat/entry.jsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useInView, useOnInView } from "react-intersection-observer";
2+
3+
function CompatibilityFixture() {
4+
const callbackRef = useOnInView(() => {});
5+
const { ref: stateRef } = useInView();
6+
7+
return (
8+
<>
9+
<div ref={callbackRef} />
10+
<div ref={stateRef} />
11+
</>
12+
);
13+
}
14+
15+
window.__COMPAT_FIXTURE__ = CompatibilityFixture;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from "@rsbuild/core";
2+
import { pluginReact } from "@rsbuild/plugin-react";
3+
4+
export default defineConfig({
5+
plugins: [pluginReact()],
6+
source: {
7+
entry: {
8+
index: "./entry.jsx",
9+
},
10+
},
11+
});

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"scripts": {
4545
"prebuild": "rm -rf dist lib",
4646
"build": "tsup && mkdir dist/esm && cp dist/index.mjs dist/esm/index.js",
47+
"compat:packed": "node scripts/compat/packed.mts",
4748
"postbuild": "attw --pack && publint && size-limit",
4849
"dev": "run-p dev:*",
4950
"dev:package": "tsup src/index.tsx --watch",
@@ -122,6 +123,8 @@
122123
"devDependencies": {
123124
"@arethetypeswrong/cli": "^0.18.2",
124125
"@biomejs/biome": "^2.3.10",
126+
"@rsbuild/core": "1.5.13",
127+
"@rsbuild/plugin-react": "1.4.2",
125128
"@size-limit/preset-small-lib": "^12.0.0",
126129
"@testing-library/jest-dom": "^6.9.1",
127130
"@testing-library/react": "^16.3.1",

0 commit comments

Comments
 (0)