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

Fix deprecated findDOMNode usage in React 19 #909

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"build": "npm run build:bundle"
}
}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,4 @@ demo/release
packages/**/*/dist/
demo/_data/version.yml

outjs/
declaration/
dist/
declaration/
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egjs/flicking",
"version": "4.12.0-snapshot",
"version": "4.12.1-react19",
"description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
"main": "dist/flicking.cjs.js",
"module": "dist/flicking.esm.js",
Expand Down Expand Up @@ -47,7 +47,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/naver/egjs-flicking"
"url": "https://github.com/jtwite/egjs-flicking"
Copy link
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?

},
"author": {
"name": "NAVER Corp."
Expand Down
4 changes: 1 addition & 3 deletions packages/react-flicking/src/react-flicking/Flicking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
: getRenderingPanels(vanillaFlicking, diff(origChildren, origChildren))
: origChildren;

return this.props.useFindDOMNode
? children.map((child, idx) => <NonStrictPanel key={child.key!} ref={this._panels[idx] as any}>{child}</NonStrictPanel>)
: children.map((child, idx) => <StrictPanel key={child.key!} ref={this._panels[idx] as any}>{child}</StrictPanel>)
return children.map((child, idx) => <StrictPanel key={child.key!} ref={this._panels[idx] as any}>{child}</StrictPanel>);
}

private _isFragment(child: React.ReactElement) {
Expand Down
8 changes: 5 additions & 3 deletions packages/react-flicking/src/react-flicking/NonStrictPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
* egjs projects are licensed under the MIT license
*/
import * as React from "react";
import { findDOMNode } from "react-dom";

class NonStrictPanel extends React.Component<{ children?: React.ReactElement }> {
private _hide: boolean = false;
private _elRef: React.RefObject<HTMLElement> = React.createRef();

public get nativeElement() { return findDOMNode(this) as HTMLElement; }
public get nativeElement() { return this._elRef.current!; }
public get rendered() { return !this._hide; }

public render() {
return this._hide
? <></>
: this.props.children;
: React.cloneElement(React.Children.only(this.props.children) as React.ReactElement, {
ref: this._elRef
});
}

public show() {
Expand Down
18 changes: 11 additions & 7 deletions packages/react-flicking/src/react-flicking/ReactElementProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ import StrictPanel from "./StrictPanel";
import NonStrictPanel from "./NonStrictPanel";

class ReactElementProvider implements ElementProvider {
private _el: StrictPanel | NonStrictPanel;
private _elRef: React.RefObject<HTMLElement>;

public get element() { return this._el.nativeElement; }
public get rendered() { return this._el.rendered; }
public get element() { return this._elRef.current!; }
public get rendered() { return this._elRef.current !== null; }

public constructor(el: StrictPanel | NonStrictPanel) {
this._el = el;
public constructor(elRef: React.RefObject<HTMLElement>) {
this._elRef = elRef;
}

public show() {
this._el.show();
if (this._elRef.current) {
this._elRef.current.style.display = "";
}
}

public hide() {
this._el.hide();
if (this._elRef.current) {
this._elRef.current.style.display = "none";
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-flicking/src/react-flicking/ReactRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class ReactRenderer extends ExternalRenderer {
protected _collectPanels() {
const flicking = getFlickingAttached(this._flicking);
const reactFlicking = this._reactFlicking;
const reactPanels = reactFlicking.reactPanels;
const reactPanels = reactFlicking.reactPanels.map(panel => panel.nativeElement);

this._panels = this._strategy.collectPanels(flicking, reactPanels);
}

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

Expand Down