Skip to content

Conversation

roxanne-baker
Copy link

@roxanne-baker roxanne-baker commented Sep 27, 2025

Details

Removes the existing error when attempting to use attachInternals in synthetic shadow and instead uses a Proxy in synthetic shadow to ensure that the shadow root returns as expected. Error message was also removed for FACE-related callback methods in synthetic shadow.

Existing tests were updated to run in synthetic shadow and new tests added to cover functionality related to other ElementInternals properties not covered by existing tests.

Does this pull request introduce a breaking change?

No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

Yes, it does include an observable change.

ElementInternals/attachInternals and FACE callbacks should now be fully supported in synthetic shadow instead of throwing errors.

GUS work item

W-19275967

@roxanne-baker roxanne-baker requested a review from a team as a code owner September 27, 2025 22:40
Copy link

Thanks for the contribution! Unfortunately we can't verify the commit author(s): roxanne.baker <r***@s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, refresh the status of this Pull Request.

@roxanne-baker roxanne-baker reopened this Sep 27, 2025
@roxanne-baker roxanne-baker force-pushed the synthetic-element-internals branch from 33a6d1e to e579965 Compare September 27, 2025 22:52
@roxanne-baker roxanne-baker changed the title feat: Add support for ElementInternals in synthetic shadow feat: add support for ElementInternals in synthetic shadow Sep 27, 2025
@roxanne-baker roxanne-baker force-pushed the synthetic-element-internals branch from e579965 to 31414f3 Compare September 29, 2025 15:52
// Ensure the DOM is in a clean state
document.body.replaceChildren();
document.head.replaceChildren();
window.__lwcResetGlobalStylesheets();
Copy link
Author

Choose a reason for hiding this comment

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

without this the stylesheet was removed after the first test, but since it was cached it wouldn't get re-added - meaning that the styles were only actually present for the first test

@roxanne-baker roxanne-baker requested a review from wjhsf September 30, 2025 15:29
Copy link
Contributor

@wjhsf wjhsf left a comment

Choose a reason for hiding this comment

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

  1. In synthetic shadow, can a user do HTMLElement.prototype.attachInternals.call(someComponent) and get access to the real shadow root (not synthetic)? Or do we already guard that?
  2. IIRC we wanted this to be an internal-only feature because synthetic shadow is deprecated, right? I think we'll need a compiler flag. Lemme double check.

roxanne-baker and others added 2 commits September 30, 2025 13:12
…ement.attachInternals/elementInternals/formAssociated/index.spec.js

Co-authored-by: Will Harney <[email protected]>
…ement.attachInternals/elementInternals/formAssociated/index.spec.js

Co-authored-by: Will Harney <[email protected]>
@roxanne-baker
Copy link
Author

  1. I didn't explicitly do anything against that but trying it seems to result in an illegal invocation error
  2. I think so - I'm not sure where to find a reference for other compiler flags in the code though, could you point me to an example I can use to learn from?

@wjhsf
Copy link
Contributor

wjhsf commented Oct 6, 2025

const __lwc_component_class_internal = _registerComponent(Test, {
  tmpl: _tmpl,
  sel: "lwc-test",
  apiVersion: 9999999
});

This is the current result of compiling an LWC component. In order to have a compile-time switch for synthetic element internals, we should add an additional property to the object, which should just reflect a boolean set in the compiler options. Because 99% of components will never set the flag, we can avoid unnecessarily increasing file sizes by only setting the property when the compiler flag is true (and setting it to 1 instead of true 📈). Here's where the object is defined:

t.objectExpression([
t.objectProperty(t.identifier(TEMPLATE_KEY), templateIdentifier),
t.objectProperty(t.identifier(COMPONENT_NAME_KEY), componentRegisteredName),
// It's important that, at this point, we have an APIVersion rather than just a number.
// The client needs to trust the server that it's providing an actual known API version
t.objectProperty(t.identifier(API_VERSION_KEY), t.numericLiteral(apiVersion)),
]),

The flag should be an optional boolean set via @lwc/compiler and piped through the packages to get to where it's needed for compilation. At runtime, you can update the metadata interface definition, then add a helper that you can use in your code.

type ComponentConstructorMetadata = {
tmpl: Template;
sel: string;
apiVersion: APIVersion;
};

export function getComponentRegisteredName(Ctor: LightningElementConstructor): string | undefined {
return registeredComponentMap.get(Ctor)?.sel;
}

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