Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@lwc/compiler/src/transformers/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as babel from '@babel/core';
import babelAsyncGeneratorFunctionsPlugin from '@babel/plugin-transform-async-generator-functions';
import babelAsyncToGenPlugin from '@babel/plugin-transform-async-to-generator';
import babelClassPropertiesPlugin from '@babel/plugin-transform-class-properties';
// import babelClassPropertiesPlugin from '@babel/plugin-transform-class-properties';
import babelObjectRestSpreadPlugin from '@babel/plugin-transform-object-rest-spread';
import lockerBabelPluginTransformUnforgeables from '@locker/babel-plugin-transform-unforgeables';
import lwcClassTransformPlugin, { type LwcBabelPluginOptions } from '@lwc/babel-plugin-component';
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function scriptTransform(

const plugins: babel.PluginItem[] = [
[lwcClassTransformPlugin, lwcBabelPluginOptions],
[babelClassPropertiesPlugin, { loose: true }],
// [babelClassPropertiesPlugin, { loose: true }],
];

if (!isAPIFeatureEnabled(APIFeature.DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION, apiVersion)) {
Expand Down
25 changes: 25 additions & 0 deletions packages/@lwc/engine-core/src/framework/invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { evaluateTemplate, setVMBeingRendered, getVMBeingRendered } from './temp
import { runWithBoundaryProtection } from './vm';
import { logOperationStart, logOperationEnd, OperationId } from './profiler';
import { LightningElement } from './base-lightning-element';
import { getDecoratorsMeta } from './decorators/register';
import type { Template } from './template';
import type { VM } from './vm';
import type { LightningElementConstructor } from './base-lightning-element';
Expand Down Expand Up @@ -72,6 +73,9 @@ export function invokeComponentConstructor(vm: VM, Ctor: LightningElementConstru
'Invalid component constructor, the class should extend LightningElement.'
);
}

// NEW: Migrate class fields to reactive system
migrateClassFieldsToReactiveSystem(vm, result);
} catch (e) {
error = Object(e);
} finally {
Expand All @@ -86,6 +90,27 @@ export function invokeComponentConstructor(vm: VM, Ctor: LightningElementConstru
}
}

function migrateClassFieldsToReactiveSystem(vm: VM, component: LightningElement) {
const def = vm.def;
const decoratorsMeta = getDecoratorsMeta(def.ctor);
const observedFields = decoratorsMeta.observedFields || {};

// Get the field names that should be observed
const fieldNames = Object.keys(observedFields);

fieldNames.forEach((fieldName) => {
// Check if the field exists on the component but not in the reactive system
if (fieldName in component && !(fieldName in vm.cmpFields)) {
// Migrate the value to the reactive system
const value = (component as any)[fieldName];
vm.cmpFields[fieldName] = value;

// Remove the direct property to ensure future access goes through reactive system
delete (component as any)[fieldName];
}
});
}

export function invokeComponentRenderMethod(vm: VM): VNodes {
const {
def: { render },
Expand Down
6 changes: 4 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2244,9 +2244,11 @@

"@lwc/eslint-plugin-lwc-internal@link:./scripts/eslint-plugin":
version "0.0.0"
uid ""

"@lwc/test-utils-lwc-internals@link:./scripts/test-utils":
version "0.0.0"
uid ""

"@napi-rs/[email protected]":
version "0.2.4"
Expand Down Expand Up @@ -8617,7 +8619,7 @@ http-assert@^1.3.0:

[email protected], [email protected], http-cache-semantics@^4.0.0, http-cache-semantics@^4.1.0, http-cache-semantics@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
resolved "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==

[email protected], http-errors@^2.0.0:
Expand Down Expand Up @@ -12714,7 +12716,7 @@ semver-truncate@^1.1.2:

[email protected], semver@^5.3.0, semver@^5.5.0, semver@^5.6.0, semver@^6.3.0, semver@^6.3.1, semver@^7.1.1, semver@^7.3.2, semver@^7.3.5, semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.3, semver@^7.7.2:
version "7.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
resolved "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==
dependencies:
lru-cache "^6.0.0"
Expand Down
Loading