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

<style> example breaks editor #1013

Closed
wbamberg opened this issue Jul 4, 2018 · 1 comment
Closed

<style> example breaks editor #1013

wbamberg opened this issue Jul 4, 2018 · 1 comment

Comments

@wbamberg
Copy link
Contributor

wbamberg commented Jul 4, 2018

The example for <style> breaks the editor UI when the CSS is edited:

html-style-bug

I have no idea why. It's possible that <style> won't be suitable for an interactive example.

@wbamberg wbamberg changed the title <style> example breaks iframe styling <style> example breaks editor Jul 4, 2018
@stephanmax
Copy link
Contributor

I think what blows up here is this code inside the render function in editor.js:

var styleElements = shadow.querySelectorAll('style'); // A

for (var styleElement in styleElements) {
    if (styleElements.hasOwnProperty(styleElement)) {
        shadow.removeChild(styleElements[styleElement]); // B
    }
}

All style elements are selected (A), including the one coming from inside the HTML editor. Since that one is not a direct child of the shadow root, calling removeChild (B) on it throws an error. The render method exits and we are left with only the div element but no more style elements.

I think deleting the div first (and the style element from the HTML editor with it), before we query the DOM, is the cheapest solution here. PR is coming right up.

schalkneethling pushed a commit that referenced this issue Jul 6, 2018
…hod (#1017)

**Problem:** Calling `removeChild` on a non-child node throws an error.

**Fix:** The cheap solution here is to delete the content coming from the HTML editor first, then query all remaining `<style>` elements (coming from CSS editor and output base styles) and remove them from shadow root.
wbamberg pushed a commit to wbamberg/interactive-examples that referenced this issue Jul 12, 2018
* upstream/master: (33 commits)
  Add HTML example for <a> (issue mdn#1014) (mdn#1022)
  fix(tabbed): load fonts as part of the editor css as @font-face does not work inside shadow dom (mdn#1015)
  html/input: Lowercase attributes (mdn#1024)
  Add color-adjust property example (mdn#1008)
  chore(deps): update dependency eslint to v5.1.0 (mdn#1023)
  chore(community): add @goodwin64 as contributor (mdn#1021)
  chore(community): add @dagolinuxoid as contributor (mdn#1020)
  chore(community): add @arai-a as contributor (mdn#1019)
  chore(community): add @ro-ka as contributor (mdn#1018)
  Issue mdn#1013 <style> elements in HTML editor break editor's render method (mdn#1017)
  chore(deps): update jest monorepo to v23.3.0 (mdn#1012)
  Issue#946 open links in new tab (mdn#1009)
  Send metric only during loading event (mdn#1011)
  fix(performance): only send loading mark inside loading event (mdn#1010)
  chore(deps): update dependency prettier to v1.13.7 (mdn#1006)
  fix(address): add name to the provided address (mdn#1004)
  chore(community): add @Arkangus as contributor (mdn#1002)
  Correct "expected output" mistake (mdn#1000)
  fix(performance): send post to kuma for custom ie-load-event-end metric (mdn#1001)
  chore(deps): update jest monorepo to v23.2.0 (mdn#993)
  ...
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

No branches or pull requests

3 participants