Skip to content

Shady Parts: improved support for mutations, plus small bugfixes #357

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

Merged
merged 10 commits into from
Jun 24, 2020

Conversation

aomarks
Copy link
Contributor

@aomarks aomarks commented Jun 10, 2020

NOTE: Recommend viewing each commit separately!

Small bugfixes:

  1. Fix ::part selector parse bug for element names with >1 dash
  2. Fix ::part selector parse bug for comma-delimited group selectors in custom property handling logic
  3. Fix bug where inserting a comment node would crash the onInsertBefore hook

Improved mutation support:

  1. Support for mutating part attribute with setAttribute and removeAttribute
  2. Support for mutating exportparts attribute with setAttribute and removeAttribute
  3. Support for dynamically inserting exportparts nodes, and moving them between shadow roots (part nodes already worked, did add more tests though).

Part of #252
Fixes #353
Fixes #354
Fixes #355

@aomarks aomarks requested a review from sorvell June 10, 2020 00:49
@aomarks aomarks requested a review from bicknellr as a code owner June 10, 2020 00:49
@wbern
Copy link

wbern commented Jun 10, 2020

This might sound greedy of me (thanks for doing this), but do you think an improvement could be made to address #81 as well? Right now slot functionality in the vue WC wrapper is basically broken because of it.

This fork fixes it by using polling, but it would be nice if the MutationObserver could be fixed in ShadyDOM. https://github.com./TeliaSweden/vue-web-component-wrapper-ie11/blob/7646d635a322363d98d3699ec8e46dc63840948b/src/index.js#L114

addShadyPartAttributes(host, parts);
}

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does more than just add the attributes. Suggest adding explanation. Also find the name parts confusing for describing an array of elements.

Copy link
Contributor Author

@aomarks aomarks Jun 10, 2020

Choose a reason for hiding this comment

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

This does more than just add the attributes. Suggest adding explanation.

Done (styleShadowParts with new jsdoc description of exactly what it does).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also find the name parts confusing for describing an array of elements.

Done, renamed to partNodes. I also updated some other spots to try and use the variables partName and partNode consistently instead of part.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, I think that improves the readability a lot.

if (!root) {
return;
}
const staleParts = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

stalePartElements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (stalePartNodes though, I've been using nodes more consistently).

<script type="module">
import {pierce, style, black, blackQuad, red, green} from './test-utils.js';

suite('exportparts attribute mutations', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add comment that state is purposefully maintained from test to test here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not actually, setup and teardown happen on every test case. Updated the initial state test description to verify initial state since I can see that would imply it sets state rather than just checks it.

});

test('move parent from grand-1 to grand-2', () => {
grand2.shadowRoot.appendChild(parent);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this work if the parent was just removed? Do you need to also patch removeChild in ShadyDOM? (If so, can file/handle as a separate issue.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like if an exportparts node is removed, then any descendant parts aren't connected, so we don't care if the shady-part attributes are stale and can safely do nothing. Once they get re-connected somewhere else we do care, but that's already handled here because of the onInsert logic. I added some removeChild calls to the test case just to ensure nothing weird is happening.

Is there another scenario I'm not thinking of?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I think that makes sense.

@aomarks aomarks requested a review from sorvell June 10, 2020 21:42
@aomarks aomarks merged commit 426ba1a into shady-parts Jun 24, 2020
@aomarks aomarks deleted the shady-parts-mutate branch June 24, 2020 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants