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

POC #5944: Just use shadow DOM instead of iframes #7616

Closed
wants to merge 5 commits into from

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Feb 13, 2024

What does this PR do?

This was discussed a few times before: we use iframes because Bootstrap uses REM units, and the host page's font-size affects them.

This issue can be resolved at the root, by just altering Bootstrap's theme to use pixels. This is done once and lasts forever.

REM brings no advantage here, it only leads us to make the app more complex with many iframed documents and unnecessary messaging.

Demo (before/after)

  1. The first thing that can be noticed is that the component loads instantly.
  2. Avoiding the iframe will also let us easily add small loading transitions instead of being so clunky
  3. Most importantly, the cost of adding new components (dev time, extension size) is reduced
Screen.Recording.mov

Drawbacks

External content, if any, will be affected by the host's CSP. Do you know if anyone is loading images in these iframes? We can actually detect them and loading them via fetch if desired.

I think the UX/DX improvement for everyone would still be worth the change.

Review tips

The code is hacky, not meant to be merged

Checklist

  • Add tests
  • New files added to src/tsconfig.strictNullChecks.json (if possible)
  • Designate a primary reviewer

1. Open https://npm.runkit.com/postcss-remtopx
2. Paste this
3. Run it

```js
const fetch = require("node-fetch@2.7.0");
const postcss = require("postcss");
const postcssRem = require("postcss-remtopx");

const bootstrapCssUrl = "https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.css";

async function fetchBootstrapCss() {
  console.log('Fetching bootstrap')
  const response = await fetch(bootstrapCssUrl);
  const bootstrapCssContent = await response.text();
  console.log('processing')
  const result = await postcss([postcssRem]).process(bootstrapCssContent);
  console.log(result.css)
}

fetchBootstrapCss();
```
@@ -20,7 +20,7 @@
<head>
<!--Uncomment this script tag to enable the React Dev Tools app-->
<!--See https://github.com/pixiebrix/pixiebrix-extension/wiki/Development-commands#react-dev-tools -->
<!-- <script src="http://localhost:8097"></script> -->
<script src="http://localhost:8097"></script>

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source Medium

Script loaded using unencrypted connection.
@fregante
Copy link
Contributor Author

Closing as iframed documents might be the way forward for PB:

However I'll likely still replace the rem/px replacement later on

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.

1 participant