-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH Improved validation #85
ENH Improved validation #85
Conversation
d08c4bd
to
de0bb19
Compare
de0bb19
to
8f4e625
Compare
326fcd0
to
0aa57cc
Compare
9a87ead
to
f78ecb4
Compare
For the |
f78ecb4
to
07ef013
Compare
7752fc7
to
10eca8d
Compare
10eca8d
to
d6a9da4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, will merge after framework PR.
d6a9da4
to
9decd5a
Compare
Works great on a page. When I try in an inline-elemental block, the first time I try to create a link and trigger validation (i.e. an invalid link), the modal just closes and reopens. |
I've spent half a day debugging this. This is seems like an extremely difficult issue to fix. Core issue is that the ElementList.js (possibly higher up) is re-rendering on validation failure, causing the nested LinkField and nested FormBuilderModal to themselves re-render. LinkFields on Page don't have this issue because they're not nested inside a react component higher up that keeps re-rendering This can be validated by putting in the following into (silverstripe/silverstripe-elemental) ElementEditor.js and putting breakpoints in and causing the validation to fail - componentDidUpdate() will trigger on the 1st validation failure. It will not trigger on the 2nd validation failure. componentDidMount() {
var x = 1;
}
componentDidUpdate() {
var x = 1;
} What's causing the re-render seems like its in the "magical blackbox" territory of JS Injector which does a bunch of stuff in registerTransforms.js and possibly redux-form. I don't really know. I've pretty confident that if we're able to get a fix for this it won't be in linkfield, it'll likely be in elemental though possibly admin instead There's an outside chance there's some cross-over with silverstripe/silverstripe-admin#1662, Debugging in entwine.js on |
Update: Max traced it to this line - making it so that Injector isn't used fixes the issue and instead we just use I've leave this code as is in this PR and look to fix or remove on this card |
For my money, passing the injected modal as a prop or memoising it seems likely to resolve this. |
I had a quick try with // https://react.dev/reference/react/memo
import React, { memo } from 'react';
const LinkModal = memo(loadComponent(`LinkModal.${handlerName}`)); Didn't work
Passing as a prop from LinkPicker.js to LinkModalContainer.js didn't seem to work either |
Max came up with a solution. I've simplied it a lot, the only part that's really needed is setting the import React, { useState } from 'react';
// ...
const [ LinkModal, setLinkModal ] = useState(null);
// ...
if (LinkModal === null) {
setLinkModal(() => loadComponent(`LinkModal.${handlerName}`));
} You can wrap setting the state in a call to |
54ee80e
to
493a294
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great locally, just a tiny docs regression
493a294
to
0099636
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Issue #17
Requires silverstripe/silverstripe-framework#11116 to be merged first before CI works