Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(ssr): add more LightningElement methods @W-16867451 #4589

Merged
merged 3 commits into from
Sep 30, 2024
Merged

Conversation

wjhsf
Copy link
Collaborator

@wjhsf wjhsf commented Sep 30, 2024

Details

Made the following changes to @lwc/ssr-runtime to better match @lwc/engine-server:

  • Adds addEventListener and removeEventListener as no-ops
  • Adds hasAttribute because we missed that last time
  • Changes the "not implemented" error for some methods to "not available"
    • Methods that don't use that specific message in @lwc/engine-server are left as-is
  • Changes some props to "not available" getters

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.
  • 💔 Yes, it does introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.
  • 🔬 Yes, it does include an observable change.

GUS work item

W-16867451

@wjhsf wjhsf requested a review from a team as a code owner September 30, 2024 17:55
Comment on lines +271 to +280
accessKey?: string;
dir?: string;
draggable?: boolean;
hidden?: boolean;
id?: string;
lang?: string;
shadowRoot?: ShadowRoot | null;
spellcheck?: boolean;
tabIndex?: number;
title?: string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aside from shadowRoot, these are all global attributes. Should they be implemented as getters/setters that just reflect onto __attrs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we'll need to implement proper property reflection. This is already handled in @lwc/engine-server because it gets it from base-lightning-element.ts in @lwc/engine-core. We should also add tests for it if they don't exist.

@@ -210,74 +181,116 @@ export class LightningElement implements PropsAvailableAtConstruction {
this.__attrs[attrName] = value;
}

hasAttribute(attrName: string): boolean {
return Boolean(this.__attrs && attrName in this.__attrs);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return Boolean(this.__attrs && attrName in this.__attrs);
return Boolean(this.__attrs && attrName in this.__attrs && this.__attrs[attrName] !== null);

Technically you can setAttribute('foo', null) and it's the same as removing it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opted to go the other way -- setAttribute('foo', null) will now remove the attribute from __attrs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whoops I was wrong on this! getAttribute returns null but setAttribute sets to string "null". 😆

Comment on lines +271 to +280
accessKey?: string;
dir?: string;
draggable?: boolean;
hidden?: boolean;
id?: string;
lang?: string;
shadowRoot?: ShadowRoot | null;
spellcheck?: boolean;
tabIndex?: number;
title?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we'll need to implement proper property reflection. This is already handled in @lwc/engine-server because it gets it from base-lightning-element.ts in @lwc/engine-core. We should also add tests for it if they don't exist.

@wjhsf wjhsf merged commit efbbf12 into master Sep 30, 2024
11 checks passed
@wjhsf wjhsf deleted the wjh/ssr-events branch September 30, 2024 20:30
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants