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

Infinite loop with 401 errors #96

Closed
EvgenyOrekhov opened this issue Apr 1, 2021 · 10 comments
Closed

Infinite loop with 401 errors #96

EvgenyOrekhov opened this issue Apr 1, 2021 · 10 comments
Labels
type: figma Figma Live Embed

Comments

@EvgenyOrekhov
Copy link

When I try to open the "Design" panel, it goes into an infinite loop trying to load the Figma file.

The following appears in the console:

image

This is my setup:

"@storybook/html": "^6.2.1",
"storybook-addon-designs": "^6.0.0-alpha.3"

.storybook/preview.js

import { withDesign } from 'storybook-addon-designs';

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' },
  controls: { expanded: true },
  decorators: [withDesign],
  design: { accessToken: '<private-access-token>' },
};

MyComponent.stories.js

// ...

export const MyComponent = Template.bind({});

MyComponent.parameters = {
  design: {
    type: 'figma',
    url: 'https://www.figma.com/file/...',
  },
};
@shamilovtim
Copy link

shamilovtim commented Apr 1, 2021

Think this is #92. Try moving the token down to the component and removing design:{} from parameters

@EvgenyOrekhov
Copy link
Author

Tried moving accessToken from .storybook/preview.js to MyComponent.stories.js, it didn't help.

@shamilovtim
Copy link

shamilovtim commented Apr 1, 2021

This helped fix my issues. I noticed you had:

import { withDesign } from 'storybook-addon-designs';

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' },
  controls: { expanded: true },
  decorators: [withDesign],
  design: { accessToken: '<private-access-token>' },
};

Instead I put withDesign on my individual components (not globally set like this)

Working repro is:

export default {
  decorators: [withDesign],
  title: 'Buttons',
  component: PrimaryButton,
}

const Template: Story<unknown> = args => <PrimaryButton {...args} />;

export const Primary = Template.bind({});
Primary.args = {
  text: 'Button',
  type: 'primary',
  onPress: () => null,
  disabled: false,
  isInProgress: false,
  compact: false
};
Primary.parameters = {
  design: {
    url: 'designURL'
  }
};

export const PrimaryDisabled = Template.bind({});
PrimaryDisabled.args = {
  ...Primary.args,
  disabled: true
};
PrimaryDisabled.parameters = {
  design: {
    url: 'designURL'
  }
};

and with this my #92 and #95 were resolved

@EvgenyOrekhov
Copy link
Author

So it's impossible to set withDesign globally? That's unfortunate. I would rather prefer to have less boilerplate code.

@shamilovtim
Copy link

shamilovtim commented Apr 1, 2021

You only have to set it on the default stories, so it's not too bad IMO

@EvgenyOrekhov
Copy link
Author

I just tried this:

.storybook/preview.js

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' },
  controls: { expanded: true },
};

MyComponent.stories.js

import { withDesign } from 'storybook-addon-designs';

export default {
  title: 'MyComponent',
  decorators: [withDesign],
  argTypes: {
    // ...
  },
};

// ...

export const MyComponent = Template.bind({});

MyComponent.parameters = {
  design: {
    type: 'figma',
    url: 'https://www.figma.com/file/...',
    accessToken: '<private-access-token>',
  },
};

It did not help.

@pocka pocka added the type: figma Figma Live Embed label Apr 2, 2021
@pocka
Copy link
Collaborator

pocka commented Apr 2, 2021

At first, this is nothing related to #92, as this issue is for type: "figma" and the Figma Live Embed Kit is loaded successfully. Also, the accessToken property is for type: "experimental-figspec", not type: "figma". Only type and url are required properties even if your file is private as loaded iframe takes care of the authentication process.


These errors are results of Figma Live Embed Kit (= scripts inside <iframe>) calling their internal(?) API and the API returns HTTP 401. From my experience, this is probably due to their API outage or session problem. If the latter, clearing cache/using private browsing/using a different browser would solve the problem.

If you believe the cause is at the addon instead of at the loaded iframe content, please provide an actual and expected behavior, not just errors.

@EvgenyOrekhov
Copy link
Author

At first, this is nothing related to #92, as this issue is for type: "figma" and the Figma Live Embed Kit is loaded successfully. Also, the accessToken property is for type: "experimental-figspec", not type: "figma". Only type and url are required properties even if your file is private as loaded iframe takes care of the authentication process.

That is very valuable information! It was not clear when I was reading the docs. I would appreciate it if you could add this information to the docs.


I figured it out. The 401 errors and the infinite loop were caused by the fact that I have the "Block third-party cookies" feature enabled in Google Chrome:

image

I added my Storybook host to exceptions and now it works:

image

Thank you!

@pocka
Copy link
Collaborator

pocka commented Apr 3, 2021

🤯

Given the world's movement toward more-privacy-focused-internet, I'll add a section of the third-party cookie stuff to docs.

@judithrocketmakers
Copy link

Worth noting that this doesn't work with Safari still, but that's because Safari has a bit of an all or nothing approach to privacy so it's the browser not the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: figma Figma Live Embed
Projects
None yet
Development

No branches or pull requests

4 participants