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

Render/mount to a detached DOM node #4197

Merged
merged 3 commits into from
Mar 4, 2022
Merged

Conversation

compulim
Copy link
Contributor

@compulim compulim commented Mar 4, 2022

Fixes #4196.

Changelog Entry

Fixed

Description

When rendering Web Chat to a detached DOM node, it should not break.

The following code should work.

const container = document.createElement('div');

window.WebChat.renderWebChat(
  {
    directLine: window.WebChat.createDirectLine({ token })
  },
  container
);

document.body.append(container);

We could not catch this during release testing as all of our samples and testing sites did not render Web Chat on a detached node.

Design

In our transcript fix (#4108), we started using getClientRects() to compute the bounding boxes.

However, when Web Chat is rendered/mounted to a detached DOM node, getClientRects() will return an empty array. We assumed it always return an array with at least one instance.

Thus, getClientsRects()[0].bottom would throw an exception saying it could not access bottom of undefined.

We looked at our production codebase and found only BasicTranscript.tsx will call getClientRects(). We have protected all instances.

Specific Changes

  • Add test to make sure rendering to detached DOM node is working
  • Update BasicTranscript.tsx to protect all getClientRects() against rendering on detached DOM node
  • Bump to 4.15.1 as this is considered QFE
  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@compulim compulim marked this pull request as ready for review March 4, 2022 11:09
@compulim compulim added the p0 Must Fix. Release-blocker label Mar 4, 2022
@compulim compulim merged commit a6b3788 into microsoft:main Mar 4, 2022
@compulim compulim deleted the fix-4196 branch March 4, 2022 17:00
@compulim compulim mentioned this pull request Mar 4, 2022
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p0 Must Fix. Release-blocker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webchat is not Loading
2 participants