Skip to content

Fix deprecated findDOMNode usage in React 19#909

Closed
jtwite wants to merge 5 commits intonaver:masterfrom
jtwite:fix-react-19-findDOMNode
Closed

Fix deprecated findDOMNode usage in React 19#909
jtwite wants to merge 5 commits intonaver:masterfrom
jtwite:fix-react-19-findDOMNode

Conversation

@jtwite
Copy link
Copy Markdown

@jtwite jtwite commented Feb 4, 2025

Update the library to remove the use of deprecated findDOMNode and replace it with a ref-based approach.

  • NonStrictPanel.tsx

    • Replace findDOMNode with React.createRef to access the DOM element.
    • Update the nativeElement getter to return the current ref.
    • Modify the render method to clone the element with the ref.
  • ReactElementProvider.ts

    • Update the constructor to accept a ref instead of a StrictPanel or NonStrictPanel.
    • Update the element getter to return the current ref.
    • Modify the show and hide methods to use the ref.
  • Flicking.tsx

    • Remove the useFindDOMNode prop and use a ref-based approach.
    • Update the _createPanelRefs method to use React.createRef.
    • Update the _getPanels method to use the new ref-based approach.
  • ReactRenderer.ts

    • Update the _collectPanels method to use the new ref-based approach.
    • Update the _createPanel method to use the new ref-based approach.
  • package-lock.json

    • Update the version to 4.12.0-snapshot.

Update the library to remove the use of deprecated `findDOMNode` and replace it with a ref-based approach.

* **NonStrictPanel.tsx**
  - Replace `findDOMNode` with `React.createRef` to access the DOM element.
  - Update the `nativeElement` getter to return the current ref.
  - Modify the `render` method to clone the element with the ref.

* **ReactElementProvider.ts**
  - Update the constructor to accept a ref instead of a `StrictPanel` or `NonStrictPanel`.
  - Update the `element` getter to return the current ref.
  - Modify the `show` and `hide` methods to use the ref.

* **Flicking.tsx**
  - Remove the `useFindDOMNode` prop and use a ref-based approach.
  - Update the `_createPanelRefs` method to use `React.createRef`.
  - Update the `_getPanels` method to use the new ref-based approach.

* **ReactRenderer.ts**
  - Update the `_collectPanels` method to use the new ref-based approach.
  - Update the `_createPanel` method to use the new ref-based approach.

* **package-lock.json**
  - Update the version to `4.12.0-snapshot`.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 4, 2025

CLA assistant check
All committers have signed the CLA.

* Add `nativeElement` getter to return the current ref
* Update `ReactElementProvider.ts` constructor to accept a ref instead of a `StrictPanel` or `NonStrictPanel`
* Update `element` getter to return the current ref
* Replace `useFindDOMNode` prop with a ref-based approach in `Flicking.tsx`
* Update `_createPanelRefs` method to use `React.createRef`
* Update `_getPanels` method to use the new ref-based approach
* Update `_collectPanels` method in `ReactRenderer.ts` to use the new ref-based approach
* Update `_createPanel` method to use the new ref-based approach
"repository": {
"type": "git",
"url": "https://github.com/naver/egjs-flicking"
"url": "https://github.com/jtwite/egjs-flicking"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @jtwite. Thank you for your contribution.
Could you restore package.json and gitignore before merging it into our main branch?

@jtwite
Copy link
Copy Markdown
Author

jtwite commented Feb 18, 2025 via email

@malangfox
Copy link
Copy Markdown
Contributor

malangfox commented Feb 28, 2025

createRef was added in later versions of React 16.
As long as we maintain support for early versions of React 16, we can't use createRef for this issue.

We are still looking into other ways to resolve this issue, so feel free to give us your insight here.

@InJaEE
Copy link
Copy Markdown

InJaEE commented Mar 5, 2025

createRef was added in later versions of React 16. As long as we maintain support for early versions of React 16, we can't use createRef for this issue.

We are still looking into other ways to resolve this issue, so feel free to give us your insight here.

@malangfox
Hello. I found that createRef is already being used in Flicking.tsx and StrictPanel.tsx. Could this be unrelated to React 16 compatibility?

@malangfox
Copy link
Copy Markdown
Contributor

malangfox commented Mar 12, 2025

@InJaEE
Thank you for checking our implementation that is something I missed. I think this PR won't cause any react version issues.
Since we have confirmed that createRef already exists in our implementation, there should be no problem with this fix.

@jtwite
Could you modify package.json and gitignore to match our main branch before merging?

@cs09g
Copy link
Copy Markdown

cs09g commented May 8, 2025

@jtwite Please update PR to get merged 😊


protected _createPanel(externalComponent: StrictPanel | NonStrictPanel | HTMLDivElement, options: PanelOptions) {
return this._strategy.createPanel(externalComponent, options);
return this._strategy.createPanel(externalComponent.nativeElement, options);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also branch if externalComponent is HTMLDivElement which does not use nativeElement?

@malangfox
Copy link
Copy Markdown
Contributor

Since there were no additional changes, We will apply the changes you left in PR #931.

@malangfox malangfox closed this Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants