Skip to content

Commit 721e0a1

Browse files
authored
fix(minor): undef MarkedList::renderMarker fn when using react compiler (#891)
* fix(minor): undef MarkedList::renderMarker fn when using react compiler * chore: use relative import and udpate test snapshot
1 parent 4072fed commit 721e0a1

File tree

6 files changed

+999
-1176
lines changed

6 files changed

+999
-1176
lines changed

examples/react-native-marked-sample/app.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
},
2727
"web": {
2828
"favicon": "./assets/favicon.png"
29+
},
30+
"experiments": {
31+
"reactCompiler": true
2932
}
3033
}
3134
}

examples/react-native-marked-sample/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@expo/metro-runtime": "~5.0.4",
15+
"babel-plugin-react-compiler": "^19.0.0-beta-af1b7da-20250417",
1516
"expo": "^53.0.13",
1617
"expo-status-bar": "~2.2.3",
1718
"react": "19.0.0",

examples/react-native-marked-sample/yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,13 @@ babel-plugin-polyfill-regenerator@^0.6.1:
16821682
dependencies:
16831683
"@babel/helper-define-polyfill-provider" "^0.6.3"
16841684

1685+
babel-plugin-react-compiler@^19.0.0-beta-af1b7da-20250417:
1686+
version "19.0.0-beta-af1b7da-20250417"
1687+
resolved "https://registry.yarnpkg.com/babel-plugin-react-compiler/-/babel-plugin-react-compiler-19.0.0-beta-af1b7da-20250417.tgz#b87eb8c306f3d16bf20dfbba76a097fa82555566"
1688+
integrity sha512-UyTCRmzpxa4H1EqJk8fWeUOzHdEA12NQZ5DrF5hyhCs+Y6f7B4pg1fkul49sRn9GPPGFgkrH4IxOtnQJ7tNXIA==
1689+
dependencies:
1690+
"@babel/types" "^7.26.0"
1691+
16851692
babel-plugin-react-native-web@~0.19.13:
16861693
version "0.19.13"
16871694
resolved "https://registry.yarnpkg.com/babel-plugin-react-native-web/-/babel-plugin-react-native-web-0.19.13.tgz#bf919bd6f18c4689dd1a528a82bda507363b953d"

src/components/MDList.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Decimal from "@jsamr/counter-style/presets/decimal";
2+
import Disc from "@jsamr/counter-style/presets/disc";
3+
import { MarkedListItem, useMarkedList } from "@jsamr/react-native-li";
4+
import React, {
5+
Fragment,
6+
type FunctionComponent,
7+
memo,
8+
type ReactNode,
9+
} from "react";
10+
import type { TextStyle, ViewStyle } from "react-native";
11+
12+
type MDListProps = {
13+
ordered: boolean;
14+
li: ReactNode[];
15+
listStyle?: ViewStyle;
16+
textStyle?: TextStyle;
17+
startIndex?: number;
18+
};
19+
20+
const MDList: FunctionComponent<MDListProps> = ({
21+
ordered,
22+
li,
23+
listStyle,
24+
textStyle,
25+
startIndex,
26+
}) => {
27+
const listProps = useMarkedList({
28+
counterRenderer: ordered ? Decimal : Disc,
29+
startIndex: startIndex,
30+
markerTextStyle: textStyle,
31+
markerBoxStyle: listStyle,
32+
length: li.length,
33+
});
34+
35+
return (
36+
<Fragment>
37+
{li.map((node, index) => (
38+
<MarkedListItem key={index} index={index} {...listProps}>
39+
{node}
40+
</MarkedListItem>
41+
))}
42+
</Fragment>
43+
);
44+
};
45+
46+
export default memo(MDList);

src/lib/Renderer.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import Decimal from "@jsamr/counter-style/presets/decimal";
2-
import Disc from "@jsamr/counter-style/presets/disc";
3-
import MarkedList from "@jsamr/react-native-li";
41
import Slugger from "github-slugger";
52
import React, { type ReactNode } from "react";
63
import {
@@ -14,6 +11,7 @@ import {
1411
type ViewStyle,
1512
} from "react-native";
1613
import MDImage from "./../components/MDImage";
14+
import MDList from "./../components/MDList";
1715
import MDSvg from "./../components/MDSvg";
1816
import MDTable from "./../components/MDTable";
1917
import { onLinkPress } from "../utils/handlers";
@@ -80,15 +78,14 @@ class Renderer implements RendererInterface {
8078
startIndex?: number,
8179
): ReactNode {
8280
return (
83-
<MarkedList
84-
counterRenderer={ordered ? Decimal : Disc}
85-
markerTextStyle={textStyle}
86-
markerBoxStyle={listStyle}
81+
<MDList
8782
key={this.getKey()}
83+
ordered={ordered}
84+
li={li}
85+
listStyle={listStyle}
86+
textStyle={textStyle}
8887
startIndex={startIndex}
89-
>
90-
{li.map((node) => node)}
91-
</MarkedList>
88+
/>
9289
);
9390
}
9491

0 commit comments

Comments
 (0)