Skip to content
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

#7670: Use <IsolatedComponent> for DocumentView, EphemeralFormContent, CustomFormComponent #8200

Merged
merged 41 commits into from
Apr 11, 2024

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Apr 8, 2024

These are the main 3 components that caused trouble with the stylesheet loads, so this PR should finally fix it.

Checklist

What does this PR do?

Discussion

It looks like every renderer has its own EmotionShadowRoot and I'm not touching that here, but I think it can/should be dropped if every component is already wrapped.

This is an example DOM of a DocumentView and a nested CustomForm

Screenshot 1

Future Work

Copy link
Contributor Author

@fregante fregante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work, except customForm.test is failing and I'm not sure why

> = (props) => (
<IsolatedComponent
name="CustomFormComponent"
noStyle={disableParentStyles}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disableParentStyles verified. See button:

Screenshot 2

const DocumentView: React.FC<DocumentViewProps> = (props) => (
<IsolatedComponent
name="DocumentView"
noStyle={disableParentStyles}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disableParentStyles verified. This is a document with a form:

Screenshot 2

> = (props) => (
<IsolatedComponent
name="EphemeralFormContent"
noStyle={props.definition.disableParentStyles}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props.definition.disableParentStyles verified:

Screenshot 3


expect(screen.queryByText("Submit")).not.toBeInTheDocument();
expect(screen.getByRole("textbox")).toBeInTheDocument();
expect(screen.getByShadowRole("textbox")).toBeInTheDocument();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure why suddenly this is required, the component was already in a shadow DOM.

For ease of use I tried mocking the EmotionShadowRoot component but that did not remove the shadow root. 🤷‍♂️ The mode is already set to open in tests too

Anyway this part now works.

@@ -228,9 +229,10 @@ describe("CustomFormRenderer", () => {
);

render(<Component {...props} />);
await waitForEffect();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appears to be needed due to the new React.lazy/Suspense usage.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await screen.findByRole("textbox"0 or similar usually works instead of await waitForEffect()

await userEvent.type(textBox, "Some text");
expect(textBox).toHaveValue("Some text");
await userEvent.click(screen.getByRole("button", { name: "Submit" }));
await userEvent.click(screen.getByShadowRole("button", { name: "Submit" }));

expect(runPipelineMock).toHaveBeenCalledOnce();

expect(dataStoreSetSpy).not.toHaveBeenCalled();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of these call assertions are failing. Can anyone look into them? The component is rendered fine, I see SET_PAGE_STATE when I click on a Form

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have time today, but I may have time tomorrow

@@ -63,8 +65,11 @@ const CustomFormComponent: React.FunctionComponent<{
resetOnSubmit?: boolean;
className?: string;
stylesheets?: string[];
disableParentStyles?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disableParentStyles removed from 2 components because now it's not the Component's responsibility to load its own stylesheets, but it's the loader's (i.e. where IsolatedComponent is called)

@@ -257,7 +252,7 @@ const createConfig = (env, options) =>
DEV_EVENT_TELEMETRY: false,
SANDBOX_LOGGING: false,
IS_BETA: process.env.PUBLIC_NAME === "-beta",
SHADOW_DOM: "closed",
SHADOW_DOM: "open",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting it to open for now. We can review it later. In reality we only need closed on injected widgets (not in the sidebar) so maybe this logic can be moved to renderWidget somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grahamlangford
Copy link
Collaborator

Looking into this now

// TODO: The parent node should instead make sure that the children fill
// the sidebar vertically (via a simple `.d-flex`), but this this requires
// verifying that other components aren't broken by this.
style={{ height: "100%" }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"h-100" restored.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I restored it as an actual className:

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, that restores the classname, but as you point out, it's not getting the stylesheet at that level.

@grahamlangford
Copy link
Collaborator

Should be good to go now

Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

return <div {...props}></div>;
},
},
}));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

Good choice. We should probably move it to __mocks__ so that it applies to all tests automatically.

However I hope that the shadow DOM isn't actually what was breaking this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userEvent was adding the value to the input, but the value wasn't submitted. We've had this issue elsewhere, we probably will end up moving it to __mocks__. We can leverage Playwright to test shadow DOMs in the future.

@fregante
Copy link
Contributor Author

Feel free to merge when ready

@grahamlangford grahamlangford merged commit 672f644 into main Apr 11, 2024
25 of 26 checks passed
@grahamlangford grahamlangford deleted the F/feature/isolated-form-and-document branch April 11, 2024 18:28
@grahamlangford grahamlangford added this to the 1.8.13 milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants