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

chore: Convert component to web component and update build workflows #47

Merged
merged 6 commits into from
Mar 7, 2024

Conversation

mrderyk
Copy link
Contributor

@mrderyk mrderyk commented Mar 5, 2024

CONTEXT

In order to avoid further CSS conflict issues (and therefore cast a wider compatibility net for our search component), we should mount search in a web component.

CHANGES

  • Mount react search button in a web component
  • Mount react search modal contents in a web component
  • Update docs site build process and scripts
  • Update git workflows
  • Update tests to work with Shadow DOM
  • Turn off sourcemaps in production code to reduce npm size by around 60%

@mrderyk mrderyk marked this pull request as draft March 5, 2024 21:43
Copy link

github-actions bot commented Mar 5, 2024

PR Preview Action v1.4.7
Preview removed because the pull request was closed.
2024-03-07 23:10 UTC

@mrderyk mrderyk force-pushed the chore/web_component branch 3 times, most recently from 3c89f5a to f08d9b5 Compare March 6, 2024 19:16
@mrderyk mrderyk marked this pull request as ready for review March 6, 2024 19:19
@mrderyk mrderyk requested a review from cjcenizal March 6, 2024 19:19
@mrderyk mrderyk changed the title [WIP] chore: Convert component to web component and update build workflows chore: Convert component to web component and update build workflows Mar 6, 2024
Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

I tested the preview by connecting the component to my own corpus and it worked great. I found a regression which I noted in my comments below.

I also found one bug with the demo site, which I don't consider blocking since it's not a regression. When I toggle the "Open results in new tab" option, it doesn't actually cause clicking on the search results to open them in a new tab.

image


- name: Build react-search Package
run: npm run build
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment relevant? Looks like copy-paste from an example, so if it's still helpful maybe we can reword it, e.g. refer to this project instead of an example project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -37,20 +41,132 @@ export const SearchModal = forwardRef(({ onClose, isOpen, children }: Props, ref
onEscapeKey={onCloseDelayed}
onClickOutside={onCloseDelayed}
// Enable manual focus return to work.
returnFocus={false}
returnFocus={true}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this supposed to return focus to the button when the modal is closed? I noticed that this isn't working in this PR, but it is working in master. So I think there's a regression regarding focus in this PR, potentially related to this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops I was trying something out here and forgot to take it out. Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrderyk mrderyk force-pushed the chore/web_component branch from f08d9b5 to a71ff14 Compare March 7, 2024 20:50
@mrderyk
Copy link
Contributor Author

mrderyk commented Mar 7, 2024

@cjcenizal I fixed the regression. The root cause was a gotcha in the naming convention of the web component's observable attributes- they are all internally converted to lower case. I handled this in react-chat, but forgot to here.

I put a comment in the code after fixing this issue, so future maintainers are aware of the problem.

@cjcenizal
Copy link
Contributor

When I run npm i and npm run docs, I see changes to both package.json and docs/package.json. Should we commit those changes?

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Tested locally and confirmed the regression is fixed! Nice work. Had one non-blocking suggestion.

// We have to be more specific when picking out the return focus element.
// This is because document.activeElement is now a custom element containing a shadow DOM
// In order to properly return focus, we key in on the actual button inside the shadow DOM.
returnFocusElRef.current = document.activeElement?.shadowRoot?.querySelector("button") as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe use getElementById to truly future-proof this, in case we add another button? By using a semantic name for the ID this might also become more readable.

@mrderyk mrderyk merged commit 91c4012 into main Mar 7, 2024
4 checks passed
@mrderyk mrderyk deleted the chore/web_component branch March 7, 2024 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants