Skip to content

Commit 9b98b4f

Browse files
ja-nimarlonicus
andauthored
Fix memory leak within the @react-facet/dom-fiber (#136)
* reverts package json changes * reverts package json changes again... * Add unit test for unsubscribing from insertBefore/fast-* component. * updates performance benchmark, formats code * removes only test and deferred mount override * updates broken test file --------- Co-authored-by: Marlon Huber-Smith <[email protected]>
1 parent c01086f commit 9b98b4f

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
'import/no-cycle': 'error',
2929
'no-unreachable': 'error',
3030
'no-undef': 'error',
31-
'eqeqeq': 'error',
31+
eqeqeq: 'error',
3232
'react-hooks/rules-of-hooks': 'error',
3333
'react-hooks/exhaustive-deps': 'error',
3434
'react/jsx-uses-react': 'error',

.github/workflows/benchmarking.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
node-version-file: '.nvmrc'
3737
cache: 'yarn'
3838
- run: yarn install --immutable
39-
- run: cd examples/benchmarking && yarn build && yarn compare mountFacetDomFiber mountReactDom 90
39+
- run: cd examples/benchmarking && yarn build && yarn compare mountFacetDomFiber mountReactDom 91
4040

4141
overhead:
4242
runs-on: ubuntu-latest

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Currently the process of updating the version of the packages is mostly manual. Before you start, first you need to make sure you have the permissions to publish the packages.
44

5-
- If there is a release branch (see __Release candidate__ below) that hasn't been merged to `main` yet now is the time to do so.
5+
- If there is a release branch (see **Release candidate** below) that hasn't been merged to `main` yet now is the time to do so.
66
- Make sure that you are logged in into your `npm` account. Use the command `yarn npm login` on the project folder to do this.
77
- While on the `main` branch.
88
- Perform a search an replace on all "package.json" files from the old version to the new. (ex `0.1.4` to `0.2.0`).
@@ -25,4 +25,4 @@ Currently the process of updating the version of the packages is mostly manual.
2525
- Create an annotated git tag by running `git tag -a v0.4.0-rc.0` (replace with the version). The tag message can be the version again.
2626
- Push commit and the tag `git push --follow-tags`.
2727
- Publish the packages by running `yarn publish --tag rc` (it will also build the packages).
28-
- We are currently not doing release notes for release candidates so you are all done! 🎉
28+
- We are currently not doing release notes for release candidates so you are all done! 🎉

packages/@react-facet/dom-fiber/src/setupHostConfig.spec.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,37 @@ describe('umnount', () => {
20412041
expect(unsubscribe).toHaveBeenCalledTimes(1)
20422042
})
20432043

2044+
it('unsubscribes from a facet (via a fast-* component) inserted using insertBefore, when the parent is unmounted', () => {
2045+
const unsubscribe = jest.fn()
2046+
2047+
const facet: Facet<string> = {
2048+
get: () => 'abc',
2049+
observe: jest.fn().mockReturnValue(unsubscribe),
2050+
}
2051+
2052+
const TestComponent = ({ show, facet }: { facet: Facet<string>; show?: boolean }) => (
2053+
<div>
2054+
{show ? <fast-text text={facet} /> : null}
2055+
<div />
2056+
</div>
2057+
)
2058+
2059+
render(<TestComponent facet={facet} />)
2060+
2061+
expect(facet.observe).toHaveBeenCalledTimes(0)
2062+
expect(unsubscribe).toHaveBeenCalledTimes(0)
2063+
2064+
render(<TestComponent facet={facet} show />)
2065+
2066+
expect(facet.observe).toHaveBeenCalledTimes(1)
2067+
expect(unsubscribe).toHaveBeenCalledTimes(0)
2068+
2069+
render(<></>)
2070+
2071+
expect(facet.observe).toHaveBeenCalledTimes(1)
2072+
expect(unsubscribe).toHaveBeenCalledTimes(1)
2073+
})
2074+
20442075
it('keeps the subscription of facets when moving in a keyed list', () => {
20452076
const unsubscribeA = jest.fn()
20462077

tsconfig.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"compilerOptions": {
33
"baseUrl": ".",
4-
"paths": {
5-
"@react-facet/core": ["packages/@react-facet/core/*"],
6-
"@react-facet/dom-fiber": ["packages/@react-facet/dom-fiber/*"],
7-
"@react-facet/dom-fiber-testing-library": ["packages/@react-facet/dom-fiber-testing-library/*"]
8-
},
4+
"paths": {
5+
"@react-facet/core": ["packages/@react-facet/core/*"],
6+
"@react-facet/dom-fiber": ["packages/@react-facet/dom-fiber/*"],
7+
"@react-facet/dom-fiber-testing-library": ["packages/@react-facet/dom-fiber-testing-library/*"]
8+
},
99
"outDir": "dist",
1010
"target": "es6",
1111
"moduleResolution": "node",

0 commit comments

Comments
 (0)