Skip to content

Commit 476f702

Browse files
authored
Merge branch 'master' into wjh/fix-release
2 parents 09feef8 + 107a414 commit 476f702

File tree

65 files changed

+792
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+792
-142
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lwc-monorepo",
3-
"version": "8.19.0",
3+
"version": "8.19.1",
44
"private": true,
55
"description": "Lightning Web Components",
66
"repository": {

packages/@lwc/aria-reflection/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
55
],
66
"name": "@lwc/aria-reflection",
7-
"version": "8.19.0",
7+
"version": "8.19.1",
88
"description": "ARIA element reflection polyfill for strings",
99
"keywords": [
1010
"aom",

packages/@lwc/babel-plugin-component/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
55
],
66
"name": "@lwc/babel-plugin-component",
7-
"version": "8.19.0",
7+
"version": "8.19.1",
88
"description": "Babel plugin to transform a LWC module",
99
"keywords": [
1010
"lwc"
@@ -47,8 +47,8 @@
4747
},
4848
"dependencies": {
4949
"@babel/helper-module-imports": "7.25.9",
50-
"@lwc/errors": "8.19.0",
51-
"@lwc/shared": "8.19.0",
50+
"@lwc/errors": "8.19.1",
51+
"@lwc/shared": "8.19.1",
5252
"line-column": "~1.0.2"
5353
},
5454
"devDependencies": {

packages/@lwc/compiler/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
55
],
66
"name": "@lwc/compiler",
7-
"version": "8.19.0",
7+
"version": "8.19.1",
88
"description": "LWC compiler",
99
"keywords": [
1010
"lwc"
@@ -52,11 +52,11 @@
5252
"@babel/plugin-transform-class-properties": "7.25.9",
5353
"@babel/plugin-transform-object-rest-spread": "7.25.9",
5454
"@locker/babel-plugin-transform-unforgeables": "0.22.0",
55-
"@lwc/babel-plugin-component": "8.19.0",
56-
"@lwc/errors": "8.19.0",
57-
"@lwc/shared": "8.19.0",
58-
"@lwc/ssr-compiler": "8.19.0",
59-
"@lwc/style-compiler": "8.19.0",
60-
"@lwc/template-compiler": "8.19.0"
55+
"@lwc/babel-plugin-component": "8.19.1",
56+
"@lwc/errors": "8.19.1",
57+
"@lwc/shared": "8.19.1",
58+
"@lwc/ssr-compiler": "8.19.1",
59+
"@lwc/style-compiler": "8.19.1",
60+
"@lwc/template-compiler": "8.19.1"
6161
}
6262
}

packages/@lwc/engine-core/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,18 @@ This experimental API enables the removal of an object's observable membrane pro
121121
This experimental API enables the addition of a signal as a trusted signal. If the [ENABLE_EXPERIMENTAL_SIGNALS](https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#lwcfeatures) feature is enabled, any signal value change will trigger a re-render.
122122

123123
If `setTrustedSignalSet` is called more than once, it will throw an error. If it is never called, then no trusted signal validation will be performed. The same `setTrustedSignalSet` API must be called on both `@lwc/engine-dom` and `@lwc/signals`.
124+
125+
### setContextKeys
126+
127+
Not intended for external use. Enables another library to establish contextful relationships via the LWC component tree. The `connectContext` and `disconnectContext` symbols that are provided are later used to identify methods that facilitate the establishment and dissolution of these contextful relationships.
128+
129+
### setTrustedContextSet()
130+
131+
Not intended for external use. This experimental API enables the addition of context as trusted context. If the [ENABLE_EXPERIMENTAL_SIGNALS](https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#lwcfeatures) feature is enabled.
132+
133+
If `setTrustedContextSet` is called more than once, it will throw an error. If it is never called, then context will not be connected.
134+
135+
### ContextBinding
136+
137+
The context object's `connectContext` and `disconnectContext` methods are called with this object when contextful components are connected and disconnected. The ContextBinding exposes `provideContext` and `consumeContext`,
138+
enabling the provision/consumption of a contextful Signal of a specified variety for the associated component.

packages/@lwc/engine-core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
55
],
66
"name": "@lwc/engine-core",
7-
"version": "8.19.0",
7+
"version": "8.19.1",
88
"description": "Core LWC engine APIs.",
99
"keywords": [
1010
"lwc"
@@ -46,9 +46,9 @@
4646
}
4747
},
4848
"dependencies": {
49-
"@lwc/features": "8.19.0",
50-
"@lwc/shared": "8.19.0",
51-
"@lwc/signals": "8.19.0"
49+
"@lwc/features": "8.19.1",
50+
"@lwc/shared": "8.19.1",
51+
"@lwc/signals": "8.19.1"
5252
},
5353
"devDependencies": {
5454
"observable-membrane": "2.0.0"

packages/@lwc/engine-core/src/framework/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ export { default as wire } from './decorators/wire';
7373
export { readonly } from './readonly';
7474

7575
export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
76-
export { setTrustedSignalSet } from '@lwc/shared';
76+
export { setContextKeys, setTrustedSignalSet, setTrustedContextSet } from '@lwc/shared';
7777
export type { Stylesheet, Stylesheets } from '@lwc/shared';
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: MIT
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6+
*/
7+
import {
8+
isUndefined,
9+
getPrototypeOf,
10+
keys,
11+
getContextKeys,
12+
ArrayFilter,
13+
ContextEventName,
14+
isTrustedContext,
15+
type ContextProvidedCallback,
16+
type ContextBinding as IContextBinding,
17+
} from '@lwc/shared';
18+
import { type VM } from '../vm';
19+
import { logWarnOnce } from '../../shared/logger';
20+
import type { Signal } from '@lwc/signals';
21+
import type { RendererAPI } from '../renderer';
22+
import type { ShouldContinueBubbling } from '../wiring/types';
23+
24+
type ContextVarieties = Map<unknown, Signal<unknown>>;
25+
26+
class ContextBinding<C extends object> implements IContextBinding<C> {
27+
component: C;
28+
#renderer: RendererAPI;
29+
#providedContextVarieties: ContextVarieties;
30+
#elm: HTMLElement;
31+
32+
constructor(vm: VM, component: C, providedContextVarieties: ContextVarieties) {
33+
this.component = component;
34+
this.#renderer = vm.renderer;
35+
this.#elm = vm.elm;
36+
this.#providedContextVarieties = providedContextVarieties;
37+
38+
// Register the component as a context provider.
39+
this.#renderer.registerContextProvider(
40+
this.#elm,
41+
ContextEventName,
42+
(contextConsumer): ShouldContinueBubbling => {
43+
// This callback is invoked when the provided context is consumed somewhere down
44+
// in the component's subtree.
45+
return contextConsumer.setNewContext(this.#providedContextVarieties);
46+
}
47+
);
48+
}
49+
50+
provideContext<V extends object>(
51+
contextVariety: V,
52+
providedContextSignal: Signal<unknown>
53+
): void {
54+
if (this.#providedContextVarieties.has(contextVariety)) {
55+
logWarnOnce(
56+
'Multiple contexts of the same variety were provided. Only the first context will be used.'
57+
);
58+
return;
59+
}
60+
this.#providedContextVarieties.set(contextVariety, providedContextSignal);
61+
}
62+
63+
consumeContext<V extends object>(
64+
contextVariety: V,
65+
contextProvidedCallback: ContextProvidedCallback
66+
): void {
67+
this.#renderer.registerContextConsumer(this.#elm, ContextEventName, {
68+
setNewContext: (providerContextVarieties: ContextVarieties): ShouldContinueBubbling => {
69+
// If the provider has the specified context variety, then it is consumed
70+
// and true is returned to stop bubbling.
71+
if (providerContextVarieties.has(contextVariety)) {
72+
contextProvidedCallback(providerContextVarieties.get(contextVariety));
73+
return true;
74+
}
75+
// Return false as context has not been found/consumed
76+
// and the consumer should continue traversing the context tree
77+
return false;
78+
},
79+
});
80+
}
81+
}
82+
83+
export function connectContext(vm: VM) {
84+
const contextKeys = getContextKeys();
85+
86+
if (isUndefined(contextKeys)) {
87+
return;
88+
}
89+
90+
const { connectContext } = contextKeys;
91+
const { component } = vm;
92+
93+
const enumerableKeys = keys(getPrototypeOf(component));
94+
const contextfulKeys = ArrayFilter.call(enumerableKeys, (enumerableKey) =>
95+
isTrustedContext((component as any)[enumerableKey])
96+
);
97+
98+
if (contextfulKeys.length === 0) {
99+
return;
100+
}
101+
102+
const providedContextVarieties: ContextVarieties = new Map();
103+
104+
try {
105+
for (let i = 0; i < contextfulKeys.length; i++) {
106+
(component as any)[contextfulKeys[i]][connectContext](
107+
new ContextBinding(vm, component, providedContextVarieties)
108+
);
109+
}
110+
} catch (err: any) {
111+
logWarnOnce(
112+
`Attempted to connect to trusted context but received the following error: ${
113+
err.message
114+
}`
115+
);
116+
}
117+
}
118+
119+
export function disconnectContext(vm: VM) {
120+
const contextKeys = getContextKeys();
121+
122+
if (!contextKeys) {
123+
return;
124+
}
125+
126+
const { disconnectContext } = contextKeys;
127+
const { component } = vm;
128+
129+
const enumerableKeys = keys(getPrototypeOf(component));
130+
const contextfulKeys = ArrayFilter.call(enumerableKeys, (enumerableKey) =>
131+
isTrustedContext((component as any)[enumerableKey])
132+
);
133+
134+
if (contextfulKeys.length === 0) {
135+
return;
136+
}
137+
138+
try {
139+
for (let i = 0; i < contextfulKeys.length; i++) {
140+
(component as any)[contextfulKeys[i]][disconnectContext](component);
141+
}
142+
} catch (err: any) {
143+
logWarnOnce(
144+
`Attempted to disconnect from trusted context but received the following error: ${
145+
err.message
146+
}`
147+
);
148+
}
149+
}

packages/@lwc/engine-core/src/framework/mutation-tracker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function componentValueObserved(vm: VM, key: PropertyKey, target: any = {
4242
isObject(target) &&
4343
!isNull(target) &&
4444
isTrustedSignal(target) &&
45+
process.env.IS_BROWSER &&
4546
// Only subscribe if a template is being rendered by the engine
4647
tro.isObserving()
4748
) {

packages/@lwc/engine-core/src/framework/renderer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
7-
import type { WireContextSubscriptionPayload } from './wiring';
7+
import type { WireContextSubscriptionCallback, WireContextSubscriptionPayload } from './wiring';
88

99
export type HostNode = any;
1010
export type HostElement = any;
@@ -76,6 +76,11 @@ export interface RendererAPI {
7676
) => E;
7777
defineCustomElement: (tagName: string, isFormAssociated: boolean) => void;
7878
ownerDocument(elm: E): Document;
79+
registerContextProvider: (
80+
element: E,
81+
adapterContextToken: string,
82+
onContextSubscription: WireContextSubscriptionCallback
83+
) => void;
7984
registerContextConsumer: (
8085
element: E,
8186
adapterContextToken: string,

0 commit comments

Comments
 (0)