-
Notifications
You must be signed in to change notification settings - Fork 601
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
FAST component observable doesn't work in create-react-app (Typescript) #4503
Comments
This is extremely odd. Can you share your project by any chance? |
Don't really have a project I can share. But I tried it multiple times and was able to replicate the issue every time. |
@anjulgarg is this using create-react-app? There are known integration issues with that package and property decorators. |
Yes. I used the guide here. |
Under the hood observable uses the I'm going to update the docs for this scenario, because https://www.fast.design/docs/integrations/react/#create-react-app doesn't address the TS integration issues. |
Thanks for that info @nicholasrice |
@nicholasrice I can confirm that decorators work when I created a react typescript from scratch and setup a custom webpack configuration. |
Turned into a docs request and assigned to @nicholasrice |
I'm also having the same issue 😢. Is there any way to make it work with Babel + Typescript? |
To give some more info, with legacy Babel decorators, the code compiles fine, but the decorators don't work because of how they are compiled as stated above ^: "plugins": [
"babel-plugin-transform-typescript-metadata",
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
] When enabling the "plugins": [
"babel-plugin-transform-typescript-metadata",
["@babel/plugin-proposal-decorators", { "legacy": false, "decoratorsBeforeExport": true }],
["@babel/plugin-proposal-class-properties", { "loose": true}]
] Error thrown at runtime:
|
Did some digging. These are the Babel plugins I am using: "plugins": [
"babel-plugin-transform-typescript-metadata",
["@babel/plugin-proposal-decorators", { "legacy": false, "decoratorsBeforeExport": true }],
["@babel/plugin-proposal-class-properties", { "loose": true}]
] I think I found a bug in the way the The way that Babel transpiles the code, the parameters will be this: The The |
It looks like you may be using the wrong version of decorators. There is no |
I switched back to Babel legacy decorators: "plugins": [
"babel-plugin-transform-typescript-metadata",
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
] I was able to find a workaround by creating my own function observable<T>(target: T, name: keyof T, p?: any): any {
const descriptor = {
set: function (value: T) {
Observable.notify(this, name);
(this as any)[`__${name}`] = value;
},
get: function () {
Observable.track(this, name as string);
return (this as any)[`__${name}`];
},
enumerable: true
};
Object.defineProperty(target, name, descriptor);
if (p?.initializer) {
target[name] = p.initializer();
}
return descriptor;
} |
Also possibly related, the |
@nicholasrice Can you take a few minutes this week to confirm that we've got this resolved with the appropriate update in our documentation? I'd like to close this out if the work's done or if not get a solution in place. |
We did, though I'm going to update it to reference this issue for future reference. |
Unable to make an observable re-render the template inside a typescript react app.
(This might be a dumb question OR I might be missing something since I am fairly new to web components.)
"react": "^17.0.2"
"@microsoft/fast-components": "^1.19.1"
"@microsoft/fast-element": "^1.0.1"
Steps to Reproduce
Clicking the Button should ideally increase the value from 0 to 1 and so on.
The text was updated successfully, but these errors were encountered: