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

#8220: Inject sandbox into document root instead of body #8777

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

mnholtz
Copy link
Collaborator

@mnholtz mnholtz commented Jul 8, 2024

What does this PR do?

  • Part of RENDER_NUNJUCKS not available within 3 seconds #8220
  • Injects the sandbox iframe into the document root instead of the document body
  • This is to address the hypothesis that web pages are removing the iframe from the DOM before the mod has the chance to use it (the assumption is that it is less likely for webpages to wipe things in the document root vs. the body)

Discussion/Demo

  • I'm able to consistently confirm that in the case of Docusign, the sandbox is always removed from the page after a certain point, causing a race with the mod component runtime: https://www.loom.com/share/e9ec1521b66e46fab93457a6ae391699
  • This change resolves the issue in the case of Docusign, at least

Future Work

  • The next PR I'm preparing
    • will remove injectIframe memoization so that we can ensure the iframe can be re-added on future brick runs if it does happen to get removed
    • and either leverage the MutationObserver approach I used to confirm behavior in the repro video (see above) or add retries to more thoroughly ensure that the iframe is on the page before executing a brick
    • throw more specific error to report if the iframe is not present on the page

Checklist

  • Added jest or playwright tests and/or storybook stories - It's possible to make a page on our playground that can replicate this scenario, but I'm not 100% if we want to write an e2e test for this before we know that this is the cause of the majority of user issues

For more information on our expectations for the PR process, see the
code review principles doc

@mnholtz mnholtz requested a review from twschiller July 8, 2024 21:53
@mnholtz mnholtz changed the title inject iframe to document root instead of body Inject sandbox into document root instead of body Jul 8, 2024
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.25%. Comparing base (8318d74) to head (9ccb875).
Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8777      +/-   ##
==========================================
+ Coverage   74.24%   74.25%   +0.01%     
==========================================
  Files        1332     1332              
  Lines       40817    40866      +49     
  Branches     7634     7642       +8     
==========================================
+ Hits        30306    30347      +41     
- Misses      10511    10519       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Jul 8, 2024

Playwright test results

passed  85 passed
flaky  1 flaky
skipped  2 skipped

Details

report  Open report ↗︎
stats  88 tests across 31 suites
duration  14 minutes, 9 seconds
commit  9ccb875

Flaky tests

edge › tests/pageEditor/saveMod.spec.ts › can save a standalone trigger mod

Skipped tests

chrome › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options
edge › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options

@twschiller twschiller requested a review from fregante July 8, 2024 22:16
@twschiller
Copy link
Contributor

@fregante any thoughts on using documentElement vs. body for the sandbox parent?

@twschiller twschiller added the bug Something isn't working label Jul 8, 2024
await waitForBody();
document.body.append(shadowWrap(iframe));
await waitForDocumentRoot();
document.documentElement.append(shadowWrap(iframe));
Copy link
Contributor

@twschiller twschiller Jul 8, 2024

Choose a reason for hiding this comment

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

Update "the body" comment. Add comment explaining where we're adding to the documentElement vs. the body

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching that

@twschiller twschiller changed the title Inject sandbox into document root instead of body #8220: Inject sandbox into document root instead of body Jul 8, 2024
Copy link
Contributor

@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.

LGTM. We do the same for the sidebar and other widgets

Copy link

github-actions bot commented Jul 8, 2024

When the PR is merged, the first loom link found on this PR will be posted to #sprint-demo on Slack. Do not edit this comment manually.

@mnholtz mnholtz merged commit 4caf3ad into main Jul 9, 2024
21 checks passed
@mnholtz mnholtz deleted the bugfix/8220_ensure_inject_sandbox branch July 9, 2024 00:13
@grahamlangford grahamlangford added this to the 2.0.5 milestone Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

4 participants