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

feat(ssr): enable @wire on getters/setters #4986

Merged
merged 13 commits into from
Dec 4, 2024
Merged

feat(ssr): enable @wire on getters/setters #4986

merged 13 commits into from
Dec 4, 2024

Conversation

wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Dec 2, 2024

Details

Copying the behavior of engine-server, the implementations of the getters/setters are ignored and they're treated just as props.

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

@wjhsf wjhsf requested a review from a team as a code owner December 2, 2024 20:48
@nolanlawson nolanlawson changed the title feat(ssr): enable @wire on getters/setters feat(ssr): enable @wire on getters/setters Dec 2, 2024
Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

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

Some minor quibbles but looks good overall

export default class Wire extends LightningElement {
@wire(adapter, { name: 'getterOnly' })
get getterOnly() {
throw new Error('get getterOnly should not be called');
Copy link
Collaborator

Choose a reason for hiding this comment

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

This component would be a good test case for integration-karma as well. engine-dom presumably works the same way.

packages/@lwc/ssr-compiler/src/compile-js/index.ts Outdated Show resolved Hide resolved
node.static
);
methodAsProp.decorators = decorators;
path.replaceWith(methodAsProp);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two things:

  1. We should clone the node.key and node.decorators for safety (or use immer).
  2. This is a bit janky because, in the case of e.g. getterWithSetter, it replaces the getter but not the setter. So you end up with:
  getterWithSetter;
  set getterWithSetter(v) {
    throw new Error("set getterWithSetter should not be called");
  }

...when we could just have getterWithSetter; alone.

Unfortunately solving this could require backtracing to find the corresponding setter/getter (since the @wire may be declared on the second one). Maybe we could use an enter/leave function, or do a pre-traversal traverse that merely notes with method declarations are @wire-decorated.

);
methodAsProp.decorators = decorators;
path.replaceWith(methodAsProp);
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we're missing a catalogWireAdapters() here. Presumably a test would fail if we needed to validate the wire ID/config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to catalog getter/setters, because they're not going to exist. The cataloging gets done by the PropertyDefinition visitor when we visit the newly-created node.

@wjhsf
Copy link
Contributor Author

wjhsf commented Dec 2, 2024

Fixes #4828.

Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

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

:shipit:

@wjhsf wjhsf merged commit 6283e34 into master Dec 4, 2024
11 checks passed
@wjhsf wjhsf deleted the wjh/wire-get-set branch December 4, 2024 17:26
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