Skip to content

Commit c1be885

Browse files
committed
chore: add changeset and update metrics baseline
Add changeset for context providers and memoization feature. Update metrics baseline to reflect current performance after optimizations.
1 parent 6c6fb14 commit c1be885

File tree

2 files changed

+186
-5
lines changed

2 files changed

+186
-5
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
'markdown-to-jsx': minor
3+
---
4+
5+
Add context providers and memoization to React, React Native, and Vue
6+
7+
Added context providers and memoization to all major renderers for better developer experience and performance.
8+
9+
**React:**
10+
- `MarkdownContext` - React context for default options
11+
- `MarkdownProvider` - Provider component to avoid prop-drilling
12+
- `useMemo` - 3-stage memoization (options, content, JSX)
13+
14+
**React Native:**
15+
- `MarkdownContext` - React context for default options
16+
- `MarkdownProvider` - Provider component to avoid prop-drilling
17+
- `useMemo` - 3-stage memoization (options, content, JSX)
18+
19+
**Vue:**
20+
- `MarkdownOptionsKey` - InjectionKey for provide/inject pattern
21+
- `MarkdownProvider` - Provider component using Vue's provide
22+
- `computed` - Reactive memoization for options, content, and JSX
23+
24+
**Benefits:**
25+
26+
1. **Avoid prop-drilling** - Set options once at the top level:
27+
```tsx
28+
<MarkdownProvider options={commonOptions}>
29+
<App>
30+
<Markdown>...</Markdown>
31+
<Markdown>...</Markdown>
32+
</App>
33+
</MarkdownProvider>
34+
```
35+
36+
2. **Performance optimization** - Content is only parsed when it actually changes, not on every render
37+
38+
3. **Fully backwards compatible** - Existing usage works unchanged, providers are optional
39+
40+
**Example:**
41+
```tsx
42+
import { MarkdownProvider } from 'markdown-to-jsx/react'
43+
44+
function App() {
45+
return (
46+
<MarkdownProvider options={{ wrapper: 'article', tagfilter: true }}>
47+
<Markdown># Page 1</Markdown>
48+
<Markdown># Page 2</Markdown>
49+
{/* Both inherit options from provider */}
50+
</MarkdownProvider>
51+
)
52+
}
53+
```
54+

scripts/metrics.baseline.json

Lines changed: 132 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@
254254
}
255255
},
256256
"parser": {
257-
"timestamp": "2025-12-16T04:04:54.770Z",
257+
"timestamp": "2025-12-16T05:00:42.963Z",
258258
"target": "parser",
259259
"inputSize": 173,
260-
"parseTime": 6.65,
260+
"parseTime": 6.89,
261261
"blockParsers": {
262262
"blockQuote": {
263263
"attempts": 70,
@@ -381,10 +381,10 @@
381381
}
382382
},
383383
"react": {
384-
"timestamp": "2025-11-30T05:32:38.442Z",
384+
"timestamp": "2025-12-16T05:04:20.136Z",
385385
"target": "react",
386386
"inputSize": 173,
387-
"parseTime": 7.86,
387+
"parseTime": 10.02,
388388
"blockParsers": {
389389
"blockQuote": {
390390
"attempts": 70,
@@ -633,5 +633,132 @@
633633
"blockParseIterations": 919,
634634
"inlineParseIterations": 1283
635635
}
636+
},
637+
"react-native": {
638+
"timestamp": "2025-12-16T04:57:28.130Z",
639+
"target": "react-native",
640+
"inputSize": 173,
641+
"parseTime": 8.98,
642+
"blockParsers": {
643+
"blockQuote": {
644+
"attempts": 70,
645+
"hits": 60
646+
},
647+
"breakThematic": {
648+
"attempts": 573,
649+
"hits": 55
650+
},
651+
"codeBlock": {
652+
"attempts": 30,
653+
"hits": 20
654+
},
655+
"codeFenced": {
656+
"attempts": 184,
657+
"hits": 21
658+
},
659+
"footnote": {
660+
"attempts": 15,
661+
"hits": 0
662+
},
663+
"frontmatter": {
664+
"attempts": 1,
665+
"hits": 1
666+
},
667+
"heading": {
668+
"attempts": 794,
669+
"hits": 787
670+
},
671+
"headingSetext": {
672+
"attempts": 1144,
673+
"hits": 11
674+
},
675+
"htmlBlock": {
676+
"attempts": 88,
677+
"hits": 25
678+
},
679+
"htmlComment": {
680+
"attempts": 6,
681+
"hits": 3
682+
},
683+
"listGfmTask": {
684+
"attempts": 20,
685+
"hits": 20
686+
},
687+
"list": {
688+
"attempts": 261,
689+
"hits": 151
690+
},
691+
"paragraph": {
692+
"attempts": 872,
693+
"hits": 311
694+
},
695+
"table": {
696+
"attempts": 40,
697+
"hits": 40
698+
}
699+
},
700+
"inlineParsers": {
701+
"breakLine": {
702+
"attempts": 5,
703+
"hits": 5
704+
},
705+
"codeInline": {
706+
"attempts": 51,
707+
"hits": 51
708+
},
709+
"escaped": {
710+
"attempts": 5,
711+
"hits": 5
712+
},
713+
"formatting": {
714+
"attempts": 392,
715+
"hits": 392
716+
},
717+
"footnoteRef": {
718+
"attempts": 15,
719+
"hits": 15
720+
},
721+
"htmlComment": {
722+
"attempts": 20,
723+
"hits": 10
724+
},
725+
"htmlElement": {
726+
"attempts": 66,
727+
"hits": 66
728+
},
729+
"image": {
730+
"attempts": 25,
731+
"hits": 25
732+
},
733+
"link": {
734+
"attempts": 51,
735+
"hits": 42
736+
},
737+
"linkAngleBrace": {
738+
"attempts": 76,
739+
"hits": 10
740+
},
741+
"linkBareUrl": {
742+
"attempts": 25,
743+
"hits": 25
744+
},
745+
"linkEmail": {
746+
"attempts": 5,
747+
"hits": 5
748+
},
749+
"linkRef": {
750+
"attempts": 44,
751+
"hits": 20
752+
},
753+
"refImage": {
754+
"attempts": 0,
755+
"hits": 0
756+
}
757+
},
758+
"operationCounts": {
759+
"totalOperations": 3348,
760+
"blockParseIterations": 919,
761+
"inlineParseIterations": 1283
762+
}
636763
}
637-
}
764+
}

0 commit comments

Comments
 (0)