Skip to content

Commit 38e1efc

Browse files
authored
add rx memo marker to memo fields (#5709)
* add rx memo marker to memo fields * unnecessary MEMO_MARKER for event key
1 parent 9b2d93e commit 38e1efc

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

reflex/components/component.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
PageNames,
3838
)
3939
from reflex.constants.compiler import SpecialAttributes
40-
from reflex.constants.state import FRONTEND_EVENT_STATE
40+
from reflex.constants.state import FRONTEND_EVENT_STATE, MEMO_MARKER
4141
from reflex.event import (
4242
EventCallback,
4343
EventChain,
@@ -2005,7 +2005,7 @@ def get_args_spec(key: str) -> types.ArgsSpec | Sequence[types.ArgsSpec]:
20052005

20062006
super()._post_init(
20072007
event_triggers={
2008-
key: EventChain.create(
2008+
key + MEMO_MARKER: EventChain.create(
20092009
value=props[key],
20102010
args_spec=get_args_spec(key),
20112011
key=key,
@@ -2016,7 +2016,9 @@ def get_args_spec(key: str) -> types.ArgsSpec | Sequence[types.ArgsSpec]:
20162016
)
20172017

20182018
to_camel_cased_props = {
2019-
format.to_camel_case(key) for key in props if key not in event_types
2019+
format.to_camel_case(key + MEMO_MARKER)
2020+
for key in props
2021+
if key not in event_types
20202022
}
20212023
self.get_props = lambda: to_camel_cased_props # pyright: ignore [reportIncompatibleVariableOverride]
20222024

@@ -2031,7 +2033,7 @@ def get_args_spec(key: str) -> types.ArgsSpec | Sequence[types.ArgsSpec]:
20312033
if key not in props_types:
20322034
continue
20332035

2034-
camel_cased_key = format.to_camel_case(key)
2036+
camel_cased_key = format.to_camel_case(key + MEMO_MARKER)
20352037

20362038
# Get the type based on the annotation.
20372039
type_ = props_types[key]

reflex/constants/state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ class StateManagerMode(str, Enum):
1515
FRONTEND_EVENT_STATE = "__reflex_internal_frontend_event_state"
1616

1717
FIELD_MARKER = "_rx_state_"
18+
MEMO_MARKER = "_rx_memo_"

tests/units/components/markdown/test_markdown.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_create_map_fn_var_subclass(cls, fn_body, fn_args, explicit_return, expe
169169
(
170170
"code",
171171
{"codeblock": syntax_highlighter_memoized_component(CodeBlock)},
172-
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(CodeBlock,{code:((Array.isArray(children)) ? children.join("\n") : children),language:_language,...props},) ); })""",
172+
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(CodeBlock,{codeRxMemo:((Array.isArray(children)) ? children.join("\n") : children),languageRxMemo:_language,...props},) ); })""",
173173
),
174174
(
175175
"code",
@@ -178,7 +178,7 @@ def test_create_map_fn_var_subclass(cls, fn_body, fn_args, explicit_return, expe
178178
ShikiHighLevelCodeBlock
179179
)
180180
},
181-
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(CodeBlock,{code:((Array.isArray(children)) ? children.join("\n") : children),language:_language,...props},) ); })""",
181+
r"""(({node, inline, className, children, ...props}) => { const match = (className || '').match(/language-(?<lang>.*)/); let _language = match ? match[1] : ''; ; return inline ? ( jsx(RadixThemesCode,{...props},children,) ) : ( jsx(CodeBlock,{codeRxMemo:((Array.isArray(children)) ? children.join("\n") : children),languageRxMemo:_language,...props},) ); })""",
182182
),
183183
],
184184
)

tests/units/components/test_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ def test_create_custom_component(my_component):
850850
"""
851851
component = rx.memo(my_component)(prop1="test", prop2=1)
852852
assert component.tag == "MyComponent"
853-
assert component.get_props() == {"prop1", "prop2"}
853+
assert component.get_props() == {"prop1RxMemo", "prop2RxMemo"}
854854
assert component.tag in CUSTOM_COMPONENTS
855855

856856

0 commit comments

Comments
 (0)