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

Cleanup protectEditing and ignore shadow roots. Fixes #17 #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

madeleineostoja
Copy link

No description provided.

Copy link
Contributor

@bedeoverend bedeoverend left a comment

Choose a reason for hiding this comment

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

Weirdness on checking for shadow root. Also this feature really needs to have tests written, if we break it, it can mean our users cannot edit anything. And it's complex what's going on (no thanks to my initial ultra confusing naming) so it's hard to know that new changes aren't breaking things.

function editableElementsIn(list) {
return Array.prototype.filter.call(list, isEditableElement);
function ignoredElementsIn(elements) {
const shouldIgnore = element => isSimplaElement(element) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

@seaneking root here isn't declared anywhere? Also I'm a bit concerned about the perf of this. We're querying for simpla-admin every time, and then also doing a contains op. The contains I'm not sure we can get around, but can just use window.SimplaAdmin to find the simpla-admin instance.

Copy link
Author

@madeleineostoja madeleineostoja May 12, 2017

Choose a reason for hiding this comment

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

Whoops! Should just check for truthiness, was previously doing a strict check but realised it wasn't necessary.

Copy link
Author

@madeleineostoja madeleineostoja May 12, 2017

Choose a reason for hiding this comment

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

And querying for a single element is performant, we're talking ridiculously miniscule gains there. But yeah sure, cleaner to use the singleton instance anyway.

Copy link
Author

@madeleineostoja madeleineostoja May 12, 2017

Choose a reason for hiding this comment

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

el.contains() is perfectly performant for our needs as well, again, talking crazy small gains otherwise. Very much premature optimization.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah fair on premature optimisation, if it becomes sluggish, then we can look at them.

@bedeoverend
Copy link
Contributor

Also there is a fair chunk changing here at once, so I'm not really confident in merging unless it's been manually tested pretty thoroughly.

@madeleineostoja
Copy link
Author

madeleineostoja commented May 12, 2017

Tested it a fair bit on simpla.io, and it's less broken than it was. Previous behavior was pretty borked on simpla.io, largely because it didn't ignore shadow roots.

I'd be confident that this has fewer edge cases than mainline, and can always push further patches if things are still broken.

@bedeoverend
Copy link
Contributor

This adds in a regression where you can't login (can't click on login button in simpla-admin), or at least in my tests that's whats happening - I'm on a converted agency bootstrap template.

Might be worth making a separate commit / PR that just ignores Shadow Roots. Don't think we should merge this unless we add some proper tests

@madeleineostoja
Copy link
Author

Can't repro the login button issue - can you provide more deets?

@bedeoverend
Copy link
Contributor

bedeoverend commented May 16, 2017

Yeah sure, sorry should have included steps. This is minimum repro:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <!-- Simpla -->
    <!-- Include Simpla and cross-browser polyfill, then init project -->
    <script src="https://unpkg.com/webcomponents.js@^0.7.24/webcomponents-lite.min.js"></script>
    <script src="https://unpkg.com/simpla@^2.0.0"></script>
    <script>
      Simpla.init('random');
    </script>
    <link rel="import" href="/bower_components/simpla-admin/simpla-admin.html">
  </head>
  <body>

  </body>
</html>

and just bower link simpla-admin for this branch. Then browser-sync up a server, then go to http://localhost:3000/#edit and try logging in.

For me, I can't click 'lets go' and hitting return doesn't work either. All clicks are disabled - can't click 'x' to exit either, though blurring / hitting escape work fine.

@madeleineostoja
Copy link
Author

Hmm okay, will try to repro later. If that is the case, with WC v1 around the corner maybe we should just leave this until we can properly observe shadow roots with the element registry. Flat out ignoring shadow roots is a little hokey anyway.

@madeleineostoja
Copy link
Author

Okay issue is that el.contains() doesn't seem to penetrate shadow roots, ie: only checks if it is contained within light dom children, which seems rather daft but there you have it.

Easy fix would be to use similar hack as master has now, or do some tree walking with el.getRootNode().host until you find simpla-admin or doc body.

@madeleineostoja madeleineostoja force-pushed the master branch 2 times, most recently from 97e5e80 to 587b55e Compare June 15, 2017 15:31
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