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

Coreify specific layout.js, CE, and BE functions #34810

Closed
wants to merge 4 commits into from

Conversation

samouri
Copy link
Member

@samouri samouri commented Jun 10, 2021

summary
Core-ifies specific functions needed for #34770.
The functions are: getRealChildNodes, isInternalOrServiceNode, and applyFillContent

Turns out that the typing for the very old function isInternalOrServiceNode has been wrong this whole time.
I wonder if our new type checking is more strict than it had originally been. Calling node.tagName and node.hasAttribute is incorrect because a Node could be a comment node or a text node. I fix that by adding a check for ELEMENT_NODE at the top.

@samouri samouri changed the title Coreify specific layout.js, CE, and BE functinos Coreify specific layout.js, CE, and BE functions Jun 10, 2021
@samouri samouri marked this pull request as ready for review June 10, 2021 16:53
@amp-owners-bot
Copy link

Hey @jridgewell! These files were changed:

src/core/dom/index.js
src/core/layout.js

return true;
}
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! More core! I think it would make sense for this whole file to live in src/core/dom/layout, with the only exception being the applyStaticLayout helpers that have dependencies on the experiment system

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! But that requires changing 100s of files import paths and so I'd rather do it separately since my main goal is to unblock #34770

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this is only used in custom-element. What's the motivation for moving it into core, rather than closer to CE?

Copy link
Contributor

Choose a reason for hiding this comment

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

Created #34818 to unblock any dependencies on layout; diff looks like 2ee75c4...cc4d48b excluding the import updates and actual moves

Copy link
Member Author

@samouri samouri Jun 10, 2021

Choose a reason for hiding this comment

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

Compiler will need to run it, and we don't want compiler to need an instance of CustomElement to run.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just a helper in custom-element.js then?

if (opt_replacedContent) {
element.classList.add('i-amphtml-replaced-content');
}
applyFillContent(element, opt_replacedContent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense for applyFillContent to be defined locally in this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Still relevant, since we don't really want other code using this instead of element.applyFillContent. Including it in core kinda implies it's fine, whereas no one will go out of their way to import it from here (except the compiler)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'm fine with that

src/custom-element.js Outdated Show resolved Hide resolved
@samouri
Copy link
Member Author

samouri commented Jun 15, 2021

This has been superseded by a few other PRs: #34818, #34858, and #34813 (comment)

@samouri samouri closed this Jun 15, 2021
@samouri samouri deleted the core-layout branch June 15, 2021 17:06
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.

3 participants