Skip to content
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

TypeError: Cannot read properties of undefined (reading 'selector') #809

Closed
work933k opened this issue Sep 1, 2023 · 1 comment
Closed
Labels
bug Classification: Something isn't working needs triage Tracking: Issue needs confirmation

Comments

@work933k
Copy link
Contributor

work933k commented Sep 1, 2023

Bug report

Hi!
I just started with Chromatic and love find it very powerfull.

I just noticed an error which only occurs in Chromatic and the Chromatic-Storybook. The weird thing is that the error only occurs via Chromatic. If i start Storybook manually, the error doesn't occur.

In Chromatic i see the following "ComponentException":

page.evaluate: Object
    at <anonymous> (/opt/capture/src/chromatic-lib/capture/playwright-renderer/playwrightRenderer.js:804:19)
    at NavigatorWatcher.waitForIdle (/opt/capture/src/chromatic-lib/capture/playwright-renderer/NavigatorWatcher.js:191:11)
    at ChromeRenderer.renderSpecOrTimeout (/opt/capture/src/chromatic-lib/capture/playwright-renderer/playwrightRenderer.js:800:20)
    at ChromeRenderer.renderSpec (/opt/capture/src/chromatic-lib/capture/playwright-renderer/playwrightRenderer.js:690:25)
    at ChromeRenderer.renderSnapshot (/opt/capture/src/chromatic-lib/capture/playwright-renderer/playwrightRenderer.js:441:21)
    at ChromeRenderer.captureSpecs (/opt/capture/src/chromatic-lib/capture/playwright-renderer/playwrightRenderer.js:313:9)
    at ChromeRenderer.executeWithCallback (/opt/capture/src/chromatic-lib/capture/playwright-renderer/playwrightRenderer.js:101:14)
    at Capture.execute (/opt/capture/src/chromatic-lib/capture/capture.js:282:5)
    at FargateWorker.processJob (/opt/capture/src/worker.ts:258:7)
    at FargateWorker.handleJob (/opt/capture/src/worker.ts:137:7)
    at FargateWorker.run (/opt/capture/src/worker.ts:50:9)
    at start (/opt/capture/src/index.ts:33:5)

When i choose to view the Storybook story in Chromatic:

TypeError: Cannot read properties of undefined (reading 'selector')
    at exports.computesTemplateFromComponent (https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:401:7531)
    at prepareMain (https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:3025)
    at https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:2633
    at https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:2526
    at cleanArgsDecorator (https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:3420)
    at https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:2507
    at https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:2526
    at https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:4049
    at hookified (https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/sb-preview/runtime.js:7:18973)
    at https://647b2a38e4a4f9dfac3a1bec-irxnfbgdit.chromatic.com/3633.6227c296.iframe.bundle.js:421:2507

The error only occurs on 1 specific Storybook story:

import { componentWrapperDecorator, Meta, moduleMetadata, StoryFn } from '@storybook/angular';
import {
  MatLegacyPaginator as MatPaginator,
  MatLegacyPaginatorModule as MatPaginatorModule,
} from '@angular/material/legacy-paginator';

import { MatLegacyButtonModule as MatButtonModule } from '@angular/material/legacy-button';

export default {
  title: 'Layout/Pagination',
  component: MatPaginator,
  decorators: [
    moduleMetadata({
      imports: [MatPaginatorModule, MatButtonModule],
    }),
    componentWrapperDecorator(
      (story) =>
        `<mat-card class="mat-card-flat">
          <mat-card-content>
            ${story}
          </mat-card-content>
        </mat-card>`
    ),
  ],
  parameters: {
    chromatic: {
      disable: true,
    },
  },
} as Meta;

const Template: StoryFn = (args: MatPaginator) => ({
  props: args,
});

export const Primary = {
  render: Template,

  args: {
    showFirstLastButtons: false,
    pageSize: 10,
    hidePageSize: true,
    length: 30,
  },
};

Is this a know issue? I suspect it has got something to do with specific package versions. This as the issue started to occur, after i upgraded to latest versions.

@work933k work933k added bug Classification: Something isn't working needs triage Tracking: Issue needs confirmation labels Sep 1, 2023
@Rohydre
Copy link

Rohydre commented Sep 20, 2023

OK, since i solved this on my own, i'll also give you my workaround.

Basically don't use the component field of Storybook, instead use a template in the render function.
I think it's a bug because storyboook try to recompile an already compiled component from a node_module. I'm not 100% sure of my word on this guess.

Anyways, your code will look like this:

...

export default {
  title: 'Layout/Pagination',
  component: MatPaginator,          <----- REMOVE THIS
  decorators: [

...    

const Template: StoryFn = (args: MatPaginator) => ({
  props: args,
  template : `<mat-paginator          
        [showFirstLastButtons]="showFirstLastButtons"
        [pageSize]="pageSize"                               <----- DO THIS INSTEAD
        [hidePageSize]="hidePageSize"
        [length]="length">
        </mat-paginator>`
});

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Classification: Something isn't working needs triage Tracking: Issue needs confirmation
Projects
None yet
Development

No branches or pull requests

3 participants