loki icon indicating copy to clipboard operation
loki copied to clipboard

createAsyncCallback doesn't work with Args API

Open donaldpipowitch opened this issue 4 years ago • 2 comments

Test Case

When createAsyncCallback() is used as part of the Args API Loki has troubles fetching the stories.

const Template = (args) => <DelayedComponent {...args} />;

export const Hello = Template.bind({});
Hello.args = {
  text: 'Hello',
  onDone: createAsyncCallback(),
};

export const World = Template.bind({});
World.args = {
  text: 'World',
  onDone: createAsyncCallback(),
};
Failed fetching stories because the server is down

As far as I can tell the server is not down.

You can rewrite it like this however:

const Template = (args) => (
  <DelayedComponent {...args} onDone={createAsyncCallback()} />
);

export const Hello = Template.bind({});
Hello.args = {
  text: 'Hello',
};

export const World = Template.bind({});
World.args = {
  text: 'World',
};

This works*, but the limitation is currently not documented.


*I'm not sure why, but I tried the same in a bigger code base and only get this:

(node:20347) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at writeFile (fs.js:1491:5)
    at go$writeFile (/Users/user/workspace/platform-front/node_modules/.pnpm/[email protected]/node_modules/graceful-fs/graceful-fs.js:138:14)
    at Object.writeFile (/Users/user/workspace/platform-front/node_modules/.pnpm/[email protected]/node_modules/graceful-fs/graceful-fs.js:135:12)
    at /Users/user/workspace/platform-front/node_modules/.pnpm/[email protected]/node_modules/fs-extra/lib/output/index.js:18:27
    at /Users/user/workspace/platform-front/node_modules/.pnpm/[email protected]/node_modules/universalify/index.js:22:54

I wasn't able to reproduce this so far.

donaldpipowitch avatar Jan 11 '22 06:01 donaldpipowitch

I also get:

/Users/emlai/src/epic-ui/node_modules/.pnpm/[email protected]/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at writeFile (node:fs:2168:5)
    at go$writeFile (/Users/emlai/src/epic-ui/node_modules/.pnpm/[email protected]/node_modules/graceful-fs/graceful-fs.js:138:14)
    at Object.writeFile (/Users/emlai/src/epic-ui/node_modules/.pnpm/[email protected]/node_modules/graceful-fs/graceful-fs.js:135:12)
    at /Users/emlai/src/epic-ui/node_modules/.pnpm/[email protected]/node_modules/fs-extra/lib/output/index.js:18:27
    at /Users/emlai/src/epic-ui/node_modules/.pnpm/[email protected]/node_modules/universalify/index.js:22:54 {
  code: 'ERR_INVALID_ARG_TYPE'
}

when running the whole visual test suite. Using --storiesFilter to run only some tests seems to not give that error enough time to pop up.

emillaine avatar Jan 12 '23 14:01 emillaine

This was a showstopper for us for a long time

Ajdija avatar Sep 21 '23 09:09 Ajdija