Skip to content

Commit 20a4d58

Browse files
authored
(@fluent/react) Don't call createParseMarkup() in the default context (#453)
1 parent 0b3a389 commit 20a4d58

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

fluent-react/src/context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { createContext } from "react";
22
import ReactLocalization from "./localization";
33

4-
export default createContext(new ReactLocalization([]));
4+
export default createContext(new ReactLocalization([], null));

fluent-react/src/localized.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function Localized(props) {
135135

136136
// If the message value doesn't contain any markup nor any HTML entities,
137137
// insert it as the only child of the wrapped component.
138-
if (!reMarkup.test(messageValue)) {
138+
if (!reMarkup.test(messageValue) || l10n.parseMarkup === null) {
139139
return cloneElement(child, localizedProps, messageValue);
140140
}
141141

fluent-react/test/localized_overlay.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,27 @@ foo = BEFORE <text-elem>Foo</text-elem> AFTER
799799
});
800800

801801
describe("Localized - custom parseMarkup", () => {
802+
test("disables the overlay logic if null", () => {
803+
const bundle = new FluentBundle();
804+
bundle.addResource(new FluentResource(`
805+
foo = test <em>null markup parser</em>
806+
`));
807+
808+
const renderer = TestRenderer.create(
809+
<LocalizationProvider bundles={[bundle]} parseMarkup={null}>
810+
<Localized id="foo">
811+
<div />
812+
</Localized>
813+
</LocalizationProvider>
814+
);
815+
816+
expect(renderer.toJSON()).toMatchInlineSnapshot(`
817+
<div>
818+
test &lt;em&gt;null markup parser&lt;/em&gt;
819+
</div>
820+
`);
821+
});
822+
802823
test("is called if defined in the context", () => {
803824
let parseMarkupCalls = [];
804825

0 commit comments

Comments
 (0)