Skip to content

Commit eedc784

Browse files
committed
Improve teardown of quill component to prevent double renders
1 parent ed3243b commit eedc784

File tree

10 files changed

+69
-52
lines changed

10 files changed

+69
-52
lines changed

dist/components/form/Form.d.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ declare const Form: {
1818
({ type, className, ...rest }: import("./components/FormCheck").FormCheckProps): React.JSX.Element;
1919
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;
2020
};
21-
RichText: {
22-
({ theme, modules, value, onChange, ...rest }: import("./components/FormRichText").QuillEditorProps): React.JSX.Element;
23-
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;
24-
};
21+
RichText: ({ modules, value, onChange, theme, ...rest }: import("./components/FormRichText").QuillEditorProps) => React.JSX.Element;
2522
DateTime: {
2623
({ className, ...rest }: import("./components/FormDateTime").FormDateTimeProps): React.JSX.Element;
2724
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;

dist/components/form/Form.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

dist/components/form/components/FormRichText.d.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ export interface QuillEditorProps {
99
theme?: string;
1010
onChange?(value: string): any;
1111
}
12-
declare const FormRichText: {
13-
({ theme, modules, value, onChange, ...rest }: QuillEditorProps): React.JSX.Element;
14-
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/Feedback").FeedbackProps>;
15-
};
12+
declare const FormRichText: ({ modules, value, onChange, theme, ...rest }: QuillEditorProps) => React.JSX.Element;
1613
export default FormRichText;
1714
//# sourceMappingURL=FormRichText.d.ts.map

dist/components/form/components/FormRichText.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

dist/components/form/components/FormRichText.js

+15-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/components/form/components/FormRichText.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -25532,35 +25532,40 @@ Quill.register({
2553225532
}, true);
2553325533

2553425534
var FormRichText = function (_a) {
25535-
var theme = _a.theme, modules = _a.modules, value = _a.value, onChange = _a.onChange, rest = __rest(_a, ["theme", "modules", "value", "onChange"]);
25536-
var editorRef = React.useRef(null);
25535+
var modules = _a.modules, value = _a.value, onChange = _a.onChange, theme = _a.theme, rest = __rest(_a, ["modules", "value", "onChange", "theme"]);
2553725536
var quillRef = React.useRef(null);
25537+
var containerRef = React.useRef(null);
2553825538
var quillOptions = __assign(__assign({}, modules), { theme: theme || 'snow' });
2553925539
var setValue = function (quillRef) {
2554025540
var delta = quillRef.clipboard.convert({ html: value });
2554125541
quillRef.setContents(delta, 'silent');
2554225542
};
2554325543
var configureListeners = function (quill) {
25544-
quill.on('text-change', function () {
25544+
quill.on(Quill.events.TEXT_CHANGE, function () {
2554525545
var _a;
2554625546
if (onChange) {
2554725547
onChange(((_a = quillRef.current) === null || _a === void 0 ? void 0 : _a.getSemanticHTML()) || '');
2554825548
}
2554925549
});
2555025550
};
2555125551
React.useEffect(function () {
25552-
if (editorRef.current) {
25553-
var quill = new Quill(editorRef.current, quillOptions);
25554-
quillRef.current = quill; // Store the Quill instance in a ref
25552+
if (containerRef.current) {
25553+
var container_1 = containerRef.current;
25554+
var editorContainer = container_1.appendChild(container_1.ownerDocument.createElement('div'));
25555+
var quill_1 = new Quill(editorContainer, quillOptions);
25556+
quillRef.current = quill_1; // Store the Quill instance in a ref
2555525557
if (value) {
25556-
setValue(quill);
25558+
setValue(quill_1);
2555725559
}
25558-
configureListeners(quill);
25560+
configureListeners(quill_1);
25561+
return function () {
25562+
container_1.innerHTML = '';
25563+
quill_1.off(Quill.events.TEXT_CHANGE);
25564+
};
2555925565
}
2556025566
}, []);
25561-
return React.createElement("div", { ref: editorRef, style: rest.style, id: rest.id });
25567+
return React.createElement("div", { ref: containerRef, style: rest.style, id: rest.id, className: rest.className });
2556225568
};
25563-
FormRichText.Feedback = Feedback$1;
2556425569

2556525570
var FormDateTime = function (_a) {
2556625571
var className = _a.className, rest = __rest(_a, ["className"]);

0 commit comments

Comments
 (0)