Custom React Component not Rendering in Perspective Designer

Hey Guys, I'm trying to upload a custom dropdown (just for testing) to ignition designer. I'm using a dropdown component my org's components library. Just to test how the component looks, I created a demo react app and rendered the component, it looks like below on my web app (which means no issue with the component).
dropdown in web at 5.50.24 PM

My Dropdown.tsx (Komodo is our internal library)

import * as React from 'react';
import {
   Component,
   ComponentMeta,
   ComponentProps,
   PComponent,
   PropertyTree,
   SizeObject
} from '@inductiveautomation/perspective-client';

import { bind } from 'bind-decorator';
import { CoreDropdown } from "@komodo-design-system/komodo-components-react";
export const COMPONENT_TYPE = "rad.display.dropdown";

interface DropdownProps {
   placeholder: string;
   options: Array<{ uid: string, label: string }>;
}

export class Dropdown extends Component<ComponentProps<DropdownProps>, { selectedOption: string[] }> {
    state = {
        selectedOption: ['']
    };

    @bind
    onOptionChange(e: any) {
        this.setState({ selectedOption: e.value });
    }
 
    render() {
        const { props, emit } = this.props;

        return (
            <div {...emit({ classes: ["dropdown"] })}>
                <CoreDropdown 
                    label="Label"
                    placeholder="Select Your Favourite Color"
                    functionality="single-select"
                    labeltype="default"
                    size="regular"
                    optionslimit={2}
                    counter={2}
                    menusize={6}
                    onChange={this.onOptionChange}
                    options={props.options}
                    selected= {this.state.selectedOption}
                />
            </div>
        );
    }
}

export class DropdownMeta implements ComponentMeta {

   getComponentType(): string {
       return COMPONENT_TYPE;
   }

   getViewComponent(): PComponent {
       return Dropdown;
   }

   getDefaultSize(): SizeObject {
       return ({
           width: 300,
           height: 200
       });
   }

   getPropsReducer(tree: PropertyTree): DropdownProps {
       return {
           placeholder: tree.read("placeholder", "Select a City"),
           options: tree.read("options", [])
       };
   }
}

client-components.ts

import {ComponentMeta, ComponentRegistry} from '@inductiveautomation/perspective-client';
import { MessengerComponent, MessengerComponentMeta } from './components/Messenger';
import { TagCounter, TagCounterMeta } from './components/TagCounter';
import { Dropdown, DropdownMeta } from './components/Dropdown';

// export so the components are referencable, e.g. `RadComponents['Image']
export {MessengerComponent, TagCounter, Dropdown};

import '../scss/main';
import '../css/dropdown';


// as new components are implemented, import them, and add their meta to this array
const components: Array<ComponentMeta> = [
    new MessengerComponentMeta(),
    new TagCounterMeta(),
    new DropdownMeta()
];

// iterate through our components, registering each one with the registry.  Don't forget to register on the Java side too!
components.forEach((c: ComponentMeta) => ComponentRegistry.register(c) );

Issue is, this component does not even show up in the designer (only the bg of the parent div renders). Below is the image:

Can anybody resolve this issue for me, stuck with this from last few days......Thank You...!!!

Check the dev tools instance you can get from the menu bar in the designer; see if there's any component error.

Normally our error boundary would show up and indicate there's something wrong visibly, but :man_shrugging:

I'm not a frontend expert by any means, so I can't offer much more advice than that.

Also, for posterity: please don't direct message me asking me to look at forum issues. I'm glad you posted this as a public topic, but I already read all public topics and DMing me (at 5 in the morning my local time) isn't going to get me to read your post or help you any faster.

3 Likes

Below is the error I see in the designer console.

19:31:34.012 [Browser Thread: b5c06936-75e6-4748-8d90-d64d31365b38] ERROR Perspective.Designer.Workspace - level: LEVEL_ERROR
message: "Refused to execute script from 'http://localhost:8088/res/radcomponents/vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-dr-a6fa70.RadComponents.js\' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled."
source: "http://localhost:8088/data/perspective/design"

Okay, so something's going wrong with the bundling or serving of your assets. I'm pretty confident we rely on the ResourceType you return when describing your BrowserResources to us to determine what mimetype to serve assets with:

            new BrowserResource(
                "rad-components-js",
                String.format("/res/%s/RadComponents.js", URL_ALIAS),
                BrowserResource.ResourceType.JS
            ),

Are you setting JS there?
Is there any error in the gateway logs about failing to find something (which would return a text/html 404 error page and explain the symptom you're observing in the designer)?

below is the complete error list from the console.

22:26:06.101 [Browser Thread: 2d9fd7ca-0657-414d-8259-552547b436a5] ERROR Perspective.Designer.Workspace - level: LEVEL_ERROR
message: "Refused to execute script from \'http://localhost:8088/res/radcomponents/vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-dr-a6fa70.RadComponents.js\' because its MIME type (\'text/html\') is not executable, and strict MIME type checking is enabled."
source: "http://localhost:8088/data/perspective/design"

22:26:06.102 [Browser Thread: 2d9fd7ca-0657-414d-8259-552547b436a5] ERROR Perspective.Designer.Workspace - level: LEVEL_ERROR
message: "ChunkLoadError: Loading chunk vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-dr-a6fa70 failed.\n(error: http://localhost:8088/res/radcomponents/vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-dr-a6fa70.RadComponents.js) undefined"
line_number: 689
source: "http://localhost:8088/res/radcomponents/RadComponents.js"

22:26:06.103 [Browser Thread: 2d9fd7ca-0657-414d-8259-552547b436a5] ERROR Perspective.Designer.Workspace - level: LEVEL_ERROR
message: "onerrorLogger: {\"stack\":\"Error: Constructor for \\\"core-dropdown#undefined\\\" was not found\\n    at initializeComponent (http://localhost:8088/res/radcomponents/RadComponents.js:2086:15)\",\"message\":\"Constructor for \\\"core-dropdown#undefined\\\" was not found\",\"name\":\"Error\",\"logData\":{\"msg\":\"unhandledrejection\",\"errorMsg\":\"Constructor for \\\"core-dropdown#undefined\\\" was not found\"}}"
line_number: 2
source: "http://localhost:8088/res/perspective/js/PerspectiveClient.b95f1df0a45c79e31b1f.js"

22:26:06.105 [Browser Thread: 2d9fd7ca-0657-414d-8259-552547b436a5] ERROR Perspective.Designer.Workspace - level: LEVEL_ERROR
message: "Uncaught (in promise) Error: Constructor for \"core-dropdown#undefined\" was not found"
line_number: 2086
source: "http://localhost:8088/res/radcomponents/RadComponents.js"

Also there are so many .js files created In /dist folders.

Is there any error in the gateway logs about failing to find something (which would return a text/html 404 error page and explain the symptom you're observing in the designer)?

Nope, Not even a single error in gateway log..... :slightly_frowning_face:

below is the log, when I do ./gradle build

Type-safe project accessors is an incubating feature.

> Configure project :web
Build was configured to prefer settings repositories over project repositories but repository 'Node.js' was added by plugin 'com.github.node-gradle.node'

> Task :web:yarn
yarn install v1.22.18
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.60s.

> Task :web:webpack

> web-example@1.0.0 build
> lerna run build

lerna notice cli v3.22.1
lerna info Executing command in 1 package: "yarn run build"
lerna info run Ran npm script 'build' in '@myCompanyNamespace/example-client' in 7.6s:
yarn run v1.22.18
$ yarn run clean && webpack --mode development
$ rimraf dist .awcache
copying [object Object] into /Users/hrushikesh.hd1/Ignition/perspective_test/komodo-component/web/build/generated-resources/mounted...
copying [object Object] into /Users/hrushikesh.hd1/Ignition/perspective_test/komodo-component/web/build/generated-resources/mounted...
assets by path *.js 641 KiB
  assets by chunk 373 KiB (id hint: vendors)
    asset vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-dr-a6fa70.RadComponents.js 46.9 KiB [emitted] (id hint: vendors) 1 related asset
    asset vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-br-df9bb0.RadComponents.js 39.5 KiB [emitted] (id hint: vendors) 1 related asset
    asset vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_custom--f1c7ba.RadComponents.js 30.1 KiB [emitted] (id hint: vendors) 1 related asset
    asset vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-se-3ad024.RadComponents.js 28.4 KiB [emitted] (id hint: vendors) 1 related asset
    asset vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-to-0f447b.RadComponents.js 28.2 KiB [emitted] (id hint: vendors) 1 related asset
    asset vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-up-0a83fa.RadComponents.js 26.4 KiB [emitted] (id hint: vendors) 1 related asset
    asset vendors-node_modules_komodo-design-system_komodo-core-web-components-dynamic_dist_esm_core-pa-b5c5ec.RadComponents.js 25.5 KiB [emitted] (id hint: vendors) 1 related asset
    + 10 assets
  + 20 assets
assets by path typings/ 917 bytes
  asset typings/components/Dropdown.d.ts 823 bytes [emitted]
  asset typings/rad-client-components.d.ts 94 bytes [emitted]
lerna success run Ran npm script 'build' in 1 package in 7.6s:
lerna success - @myCompanyNamespace/example-client
asset RadComponents.css 441 bytes [emitted] (name: RadComponents)
Entrypoint RadComponents 157 KiB (141 KiB) = RadComponents.css 441 bytes RadComponents.js 157 KiB 1 auxiliary asset
runtime modules 7.14 KiB 12 modules
orphan modules 2.49 KiB [orphan] 2 modules
modules by path ../../node_modules/@komodo-design-system/ 506 KiB
  modules by path ../../node_modules/@komodo-design-system/komodo-core-web-components-dynamic/dist/esm/*.js 488 KiB 39 modules
  modules by path ../../node_modules/@komodo-design-system/komodo-components-react-dynamic/dist/ 17.8 KiB 8 modules
  + 2 modules
modules by path ./ 3.14 KiB (javascript) 0 bytes (css/mini-extract)
  modules by path ./typescript/ 3.09 KiB 2 modules
  modules by path ./scss/*.scss 50 bytes (javascript) 0 bytes (css/mini-extract) 2 modules
external "PerspectiveClient" 42 bytes [built] [code generated]
external "React" 42 bytes [built] [code generated]
../../node_modules/bind-decorator/index.js 1.01 KiB [built] [code generated]
external "ReactDOM" 42 bytes [built] [code generated]
webpack 5.72.0 compiled successfully in 4198 ms
Done in 7.34s.

:person_shrugging:

My best guess is that you're getting a 404. Couldn't tell you why for sure without loading your module in an IDE and setting breakpoints, and I don't have time to do that. Unfortunately there's no paid option for module dev support, so if you're able to, you're welcome to post your module publicly somewhere and maybe someone can see what's wrong and help you out, but without that we're both flying blind.

That's correct as well, but I can't share the org's internal component things. This error only occurs when I use my org's component library. I'll try to figure things out and will update this thread if I find a solution.

Thank You...... :smile:

1 Like

Hey @PGriffith , I solved it.... so the RadComponents.js had dependency on some other .js files from the dist folder (the image which I added above), which were not copied to web.jar. I asked AI to configure the webpack.config.js to add those as well. Now it works..... :partying_face:

And u were correct, the 404 error I saw in chrome dev tools and understood that error was related to file missing.

2 Likes

Nice, glad you were able to get it working.