Skip to content

Commit

Permalink
fix: replaceable vnode caused memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Dec 19, 2024
1 parent 36a311c commit 5de9c45
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 54 deletions.
5 changes: 2 additions & 3 deletions src/_internal/icons/Cancel.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'cancel',
export default replaceable('cancel', () => (
<svg viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g fill="currentColor" fill-rule="nonzero">
<path d="M2.58859116,2.7156945 L2.64644661,2.64644661 C2.82001296,2.47288026 3.08943736,2.45359511 3.2843055,2.58859116 L3.35355339,2.64644661 L8,7.293 L12.6464466,2.64644661 C12.8417088,2.45118446 13.1582912,2.45118446 13.3535534,2.64644661 C13.5488155,2.84170876 13.5488155,3.15829124 13.3535534,3.35355339 L8.707,8 L13.3535534,12.6464466 C13.5271197,12.820013 13.5464049,13.0894374 13.4114088,13.2843055 L13.3535534,13.3535534 C13.179987,13.5271197 12.9105626,13.5464049 12.7156945,13.4114088 L12.6464466,13.3535534 L8,8.707 L3.35355339,13.3535534 C3.15829124,13.5488155 2.84170876,13.5488155 2.64644661,13.3535534 C2.45118446,13.1582912 2.45118446,12.8417088 2.64644661,12.6464466 L7.293,8 L2.64644661,3.35355339 C2.47288026,3.17998704 2.45359511,2.91056264 2.58859116,2.7156945 L2.64644661,2.64644661 L2.58859116,2.7156945 Z"></path>
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Clear.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'clear',
export default replaceable('clear', () => (
<svg viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g fill="currentColor" fill-rule="nonzero">
<path d="M8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 C2,4.6862915 4.6862915,2 8,2 Z M6.5343055,5.83859116 C6.33943736,5.70359511 6.07001296,5.72288026 5.89644661,5.89644661 L5.89644661,5.89644661 L5.83859116,5.9656945 C5.70359511,6.16056264 5.72288026,6.42998704 5.89644661,6.60355339 L5.89644661,6.60355339 L7.293,8 L5.89644661,9.39644661 L5.83859116,9.4656945 C5.70359511,9.66056264 5.72288026,9.92998704 5.89644661,10.1035534 L5.89644661,10.1035534 L5.9656945,10.1614088 C6.16056264,10.2964049 6.42998704,10.2771197 6.60355339,10.1035534 L6.60355339,10.1035534 L8,8.707 L9.39644661,10.1035534 L9.4656945,10.1614088 C9.66056264,10.2964049 9.92998704,10.2771197 10.1035534,10.1035534 L10.1035534,10.1035534 L10.1614088,10.0343055 C10.2964049,9.83943736 10.2771197,9.57001296 10.1035534,9.39644661 L10.1035534,9.39644661 L8.707,8 L10.1035534,6.60355339 L10.1614088,6.5343055 C10.2964049,6.33943736 10.2771197,6.07001296 10.1035534,5.89644661 L10.1035534,5.89644661 L10.0343055,5.83859116 C9.83943736,5.70359511 9.57001296,5.72288026 9.39644661,5.89644661 L9.39644661,5.89644661 L8,7.293 L6.60355339,5.89644661 Z" />
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Close.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'close',
export default replaceable('close', () => (
<svg
viewBox="0 0 12 12"
version="1.1"
Expand All @@ -15,4 +14,4 @@ export default replaceable(
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Date.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'date',
export default replaceable('date', () => (
<svg
width="28px"
height="28px"
Expand All @@ -16,4 +15,4 @@ export default replaceable(
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Download.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'download',
export default replaceable('download', () => (
<svg viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g fill="currentColor" fill-rule="nonzero">
<path d="M3.5,13 L12.5,13 C12.7761424,13 13,13.2238576 13,13.5 C13,13.7454599 12.8231248,13.9496084 12.5898756,13.9919443 L12.5,14 L3.5,14 C3.22385763,14 3,13.7761424 3,13.5 C3,13.2545401 3.17687516,13.0503916 3.41012437,13.0080557 L3.5,13 L12.5,13 L3.5,13 Z M7.91012437,1.00805567 L8,1 C8.24545989,1 8.44960837,1.17687516 8.49194433,1.41012437 L8.5,1.5 L8.5,10.292 L11.1819805,7.6109127 C11.3555469,7.43734635 11.6249713,7.4180612 11.8198394,7.55305725 L11.8890873,7.6109127 C12.0626536,7.78447906 12.0819388,8.05390346 11.9469427,8.2487716 L11.8890873,8.31801948 L8.35355339,11.8535534 C8.17998704,12.0271197 7.91056264,12.0464049 7.7156945,11.9114088 L7.64644661,11.8535534 L4.1109127,8.31801948 C3.91565056,8.12275734 3.91565056,7.80617485 4.1109127,7.6109127 C4.28447906,7.43734635 4.55390346,7.4180612 4.7487716,7.55305725 L4.81801948,7.6109127 L7.5,10.292 L7.5,1.5 C7.5,1.25454011 7.67687516,1.05039163 7.91012437,1.00805567 L8,1 L7.91012437,1.00805567 Z" />
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'error',
export default replaceable('error', () => (
<svg viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill-rule="evenodd">
<g fill-rule="nonzero">
<path d="M24,4 C35.045695,4 44,12.954305 44,24 C44,35.045695 35.045695,44 24,44 C12.954305,44 4,35.045695 4,24 C4,12.954305 12.954305,4 24,4 Z M17.8838835,16.1161165 L17.7823881,16.0249942 C17.3266086,15.6583353 16.6733914,15.6583353 16.2176119,16.0249942 L16.1161165,16.1161165 L16.0249942,16.2176119 C15.6583353,16.6733914 15.6583353,17.3266086 16.0249942,17.7823881 L16.1161165,17.8838835 L22.233,24 L16.1161165,30.1161165 L16.0249942,30.2176119 C15.6583353,30.6733914 15.6583353,31.3266086 16.0249942,31.7823881 L16.1161165,31.8838835 L16.2176119,31.9750058 C16.6733914,32.3416647 17.3266086,32.3416647 17.7823881,31.9750058 L17.8838835,31.8838835 L24,25.767 L30.1161165,31.8838835 L30.2176119,31.9750058 C30.6733914,32.3416647 31.3266086,32.3416647 31.7823881,31.9750058 L31.8838835,31.8838835 L31.9750058,31.7823881 C32.3416647,31.3266086 32.3416647,30.6733914 31.9750058,30.2176119 L31.8838835,30.1161165 L25.767,24 L31.8838835,17.8838835 L31.9750058,17.7823881 C32.3416647,17.3266086 32.3416647,16.6733914 31.9750058,16.2176119 L31.8838835,16.1161165 L31.7823881,16.0249942 C31.3266086,15.6583353 30.6733914,15.6583353 30.2176119,16.0249942 L30.1161165,16.1161165 L24,22.233 L17.8838835,16.1161165 L17.7823881,16.0249942 L17.8838835,16.1161165 Z" />
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Info.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'info',
export default replaceable('info', () => (
<svg viewBox="0 0 28 28" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill-rule="evenodd">
<g fill-rule="nonzero">
<path d="M14,2 C20.6274,2 26,7.37258 26,14 C26,20.6274 20.6274,26 14,26 C7.37258,26 2,20.6274 2,14 C2,7.37258 7.37258,2 14,2 Z M14,11 C13.4477,11 13,11.4477 13,12 L13,12 L13,20 C13,20.5523 13.4477,21 14,21 C14.5523,21 15,20.5523 15,20 L15,20 L15,12 C15,11.4477 14.5523,11 14,11 Z M14,6.75 C13.3096,6.75 12.75,7.30964 12.75,8 C12.75,8.69036 13.3096,9.25 14,9.25 C14.6904,9.25 15.25,8.69036 15.25,8 C15.25,7.30964 14.6904,6.75 14,6.75 Z" />
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Retry.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'retry',
export default replaceable('retry', () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path
d="M320,146s24.36-12-64-12A160,160,0,1,0,416,294"
Expand All @@ -13,4 +12,4 @@ export default replaceable(
style="fill: none; stroke: currentcolor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 32px;"
/>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/RotateClockwise.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'rotateClockwise',
export default replaceable('rotateClockwise', () => (
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M3 10C3 6.13401 6.13401 3 10 3C13.866 3 17 6.13401 17 10C17 12.7916 15.3658 15.2026 13 16.3265V14.5C13 14.2239 12.7761 14 12.5 14C12.2239 14 12 14.2239 12 14.5V17.5C12 17.7761 12.2239 18 12.5 18H15.5C15.7761 18 16 17.7761 16 17.5C16 17.2239 15.7761 17 15.5 17H13.8758C16.3346 15.6357 18 13.0128 18 10C18 5.58172 14.4183 2 10 2C5.58172 2 2 5.58172 2 10C2 10.2761 2.22386 10.5 2.5 10.5C2.77614 10.5 3 10.2761 3 10Z"
Expand All @@ -15,4 +14,4 @@ export default replaceable(
>
</path>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/RotateCounterclockwise.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'rotateClockwise',
export default replaceable('rotateClockwise', () => (
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M17 10C17 6.13401 13.866 3 10 3C6.13401 3 3 6.13401 3 10C3 12.7916 4.63419 15.2026 7 16.3265V14.5C7 14.2239 7.22386 14 7.5 14C7.77614 14 8 14.2239 8 14.5V17.5C8 17.7761 7.77614 18 7.5 18H4.5C4.22386 18 4 17.7761 4 17.5C4 17.2239 4.22386 17 4.5 17H6.12422C3.66539 15.6357 2 13.0128 2 10C2 5.58172 5.58172 2 10 2C14.4183 2 18 5.58172 18 10C18 10.2761 17.7761 10.5 17.5 10.5C17.2239 10.5 17 10.2761 17 10Z"
Expand All @@ -15,4 +14,4 @@ export default replaceable(
>
</path>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Success.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'success',
export default replaceable('success', () => (
<svg viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill-rule="evenodd">
<g fill-rule="nonzero">
<path d="M24,4 C35.045695,4 44,12.954305 44,24 C44,35.045695 35.045695,44 24,44 C12.954305,44 4,35.045695 4,24 C4,12.954305 12.954305,4 24,4 Z M32.6338835,17.6161165 C32.1782718,17.1605048 31.4584514,17.1301307 30.9676119,17.5249942 L30.8661165,17.6161165 L20.75,27.732233 L17.1338835,24.1161165 C16.6457281,23.6279612 15.8542719,23.6279612 15.3661165,24.1161165 C14.9105048,24.5717282 14.8801307,25.2915486 15.2749942,25.7823881 L15.3661165,25.8838835 L19.8661165,30.3838835 C20.3217282,30.8394952 21.0415486,30.8698693 21.5323881,30.4750058 L21.6338835,30.3838835 L32.6338835,19.3838835 C33.1220388,18.8957281 33.1220388,18.1042719 32.6338835,17.6161165 Z" />
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Time.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'time',
export default replaceable('time', () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path
d="M256,64C150,64,64,150,64,256s86,192,192,192,192-86,192-192S362,64,256,64Z"
Expand All @@ -24,4 +23,4 @@ export default replaceable(
"
/>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/To.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'to',
export default replaceable('to', () => (
<svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g fill="currentColor" fill-rule="nonzero">
<path d="M11.2654,3.20511 C10.9644,2.92049 10.4897,2.93371 10.2051,3.23464 C9.92049,3.53558 9.93371,4.01027 10.2346,4.29489 L15.4737,9.25 L2.75,9.25 C2.33579,9.25 2,9.58579 2,10.0000012 C2,10.4142 2.33579,10.75 2.75,10.75 L15.476,10.75 L10.2346,15.7073 C9.93371,15.9919 9.92049,16.4666 10.2051,16.7675 C10.4897,17.0684 10.9644,17.0817 11.2654,16.797 L17.6826,10.7276 C17.8489,10.5703 17.9489,10.3702 17.9826,10.1614 C17.994,10.1094 18,10.0554 18,10.0000012 C18,9.94241 17.9935,9.88633 17.9812,9.83246 C17.9462,9.62667 17.8467,9.42976 17.6826,9.27455 L11.2654,3.20511 Z" />
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Trash.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'trash',
export default replaceable('trash', () => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path
d="M432,144,403.33,419.74A32,32,0,0,1,371.55,448H140.46a32,32,0,0,1-31.78-28.26L80,144"
Expand Down Expand Up @@ -36,4 +35,4 @@ export default replaceable(
>
</line>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/Warning.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'warning',
export default replaceable('warning', () => (
<svg viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill-rule="evenodd">
<g fill-rule="nonzero">
<path d="M12,2 C17.523,2 22,6.478 22,12 C22,17.522 17.523,22 12,22 C6.477,22 2,17.522 2,12 C2,6.478 6.477,2 12,2 Z M12.0018002,15.0037242 C11.450254,15.0037242 11.0031376,15.4508407 11.0031376,16.0023869 C11.0031376,16.553933 11.450254,17.0010495 12.0018002,17.0010495 C12.5533463,17.0010495 13.0004628,16.553933 13.0004628,16.0023869 C13.0004628,15.4508407 12.5533463,15.0037242 12.0018002,15.0037242 Z M11.99964,7 C11.4868042,7.00018474 11.0642719,7.38637706 11.0066858,7.8837365 L11,8.00036004 L11.0018003,13.0012393 L11.00857,13.117858 C11.0665141,13.6151758 11.4893244,14.0010638 12.0021602,14.0008793 C12.514996,14.0006946 12.9375283,13.6145023 12.9951144,13.1171428 L13.0018002,13.0005193 L13,7.99964009 L12.9932303,7.8830214 C12.9352861,7.38570354 12.5124758,6.99981552 11.99964,7 Z" />
</g>
</g>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/ZoomIn.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'zoomIn',
export default replaceable('zoomIn', () => (
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M11.5 8.5C11.5 8.22386 11.2761 8 11 8H9V6C9 5.72386 8.77614 5.5 8.5 5.5C8.22386 5.5 8 5.72386 8 6V8H6C5.72386 8 5.5 8.22386 5.5 8.5C5.5 8.77614 5.72386 9 6 9H8V11C8 11.2761 8.22386 11.5 8.5 11.5C8.77614 11.5 9 11.2761 9 11V9H11C11.2761 9 11.5 8.77614 11.5 8.5Z"
Expand All @@ -15,4 +14,4 @@ export default replaceable(
>
</path>
</svg>
)
))
5 changes: 2 additions & 3 deletions src/_internal/icons/ZoomOut.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { h } from 'vue'
import { replaceable } from './replaceable'

export default replaceable(
'zoomOut',
export default replaceable('zoomOut', () => (
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M11 8C11.2761 8 11.5 8.22386 11.5 8.5C11.5 8.77614 11.2761 9 11 9H6C5.72386 9 5.5 8.77614 5.5 8.5C5.5 8.22386 5.72386 8 6 8H11Z"
Expand All @@ -15,4 +14,4 @@ export default replaceable(
>
</path>
</svg>
)
))
12 changes: 9 additions & 3 deletions src/_internal/icons/replaceable.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import type { VNode } from 'vue'
import type { GlobalIconConfig } from '../../config-provider/src/internal-interface'
import { upperFirst } from 'lodash-es'
import { defineComponent, inject } from 'vue'
import { defineComponent, h, inject } from 'vue'
import { configProviderInjectionKey } from '../../config-provider/src/context'

export function replaceable(name: keyof GlobalIconConfig, icon: JSX.Element) {
export function replaceable(name: keyof GlobalIconConfig, icon: () => VNode) {
const IconComponent = defineComponent({
render() {
return icon()
}
})
return defineComponent({
name: upperFirst(name),
setup() {
Expand All @@ -13,7 +19,7 @@ export function replaceable(name: keyof GlobalIconConfig, icon: JSX.Element) {
)?.mergedIconsRef
return () => {
const iconOverride = mergedIconsRef?.value?.[name]
return iconOverride ? iconOverride() : icon
return iconOverride ? iconOverride() : <IconComponent />
}
}
})
Expand Down
Loading

0 comments on commit 5de9c45

Please sign in to comment.