Skip to content

feat(wire): allow arbitrary computed properties in @wire config @W-17206172#5183

Closed
wjhsf wants to merge 18 commits intomasterfrom
wjh/rewire
Closed

feat(wire): allow arbitrary computed properties in @wire config @W-17206172#5183
wjhsf wants to merge 18 commits intomasterfrom
wjh/rewire

Conversation

@wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Jan 31, 2025

Details

In #3955, we updated @wire to allow configs with computed properties, e.g. { [symbol]: '$prop' }. Because of the way the config gets compiled, a computed key like [Math.random()] would return a different value every time. To avoid that, the original implementation for computed properties only allowed a limited subset of expressions (specifically, literals and const variables). In this PR, we update the compiler to store a snapshot of the computed keys, so that the values do not change. This enables us to now allow any arbitrary value as a config key.

As an example, these all used to be forbidden, but are now allowed.

@wire(adapter, { [{ toString: Date.now }]: 'weird but valid JS' }) one;
@wire(adapter, { [`number: ${Math.random()`]: 12345 }) two;
import something from 'somewhere';
@wire(adapter, { [something]: '$value' }) three;

Closes #3956.

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.

GUS work item

@wjhsf wjhsf requested a review from a team as a code owner January 31, 2025 19:49
@jhefferman-sfdc
Copy link
Contributor

Conflicting files

@wjhsf wjhsf enabled auto-merge (squash) February 5, 2025 17:30
@wjhsf wjhsf disabled auto-merge February 5, 2025 17:32
@wjhsf wjhsf enabled auto-merge (squash) February 5, 2025 17:32
@wjhsf
Copy link
Contributor Author

wjhsf commented Feb 26, 2025

Nobody asked for this, and there's some risk in things getting explode-y, so we'll hold off on the implementation.

@wjhsf wjhsf closed this Feb 26, 2025
auto-merge was automatically disabled February 26, 2025 21:37

Pull request was closed

@wjhsf wjhsf deleted the wjh/rewire branch October 15, 2025 19:37
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.

@wire computed properties should be restricted to values that cannot change

2 participants