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

A livereload triggered by Webpack leaves the add-on in a bad state #97

Open
jpzwarte opened this issue Feb 18, 2023 · 1 comment
Open

Comments

@jpzwarte
Copy link

jpzwarte commented Feb 18, 2023

The scenario:

  1. This is with @storybook/web-components-webpack5@7.0.0-beta.49, msw-storybook-addon@1.7.0 and msw@0.49.3
  2. Force reload (or restart storybook): msw intercepts the backend call fine; everything works as expected
  3. Something in the code has been changed, which triggers storybook/webpack to livereload
  4. After livereload, the backend call is no longer intercepted by msw and causes a 404 (and a broken story)

CleanShot 2023-02-18 at 10 19 33@2x

The story:

import type { Entity } from '../data-service.js';
import type { StoryObj } from '@storybook/web-components';
import type { RouterLocation } from '@vaadin/router';
import { html } from 'lit';
import { rest } from 'msw';
import './register.js';

export default {
  title: 'Example/Details',
  args: {
    id: '0'
  },
  render: ({ id }: { id: string }) =>
    html`<mg-details .location=${{ params: { id: id } } as unknown as RouterLocation}></mg-details>`,
  parameters: {
    layout: 'fullscreen'
  }
};

const ENTITIES: Entity[] = [
  {
    id: '0',
    name: 'Foo bar',
    description: 'Non laboris aliqua esse consequat aliquip amet culpa do irure anim nulla veniam.',
    approved: true,
    createdAt: new Date().toISOString()
  }
];

export const Desktop: StoryObj = {
  parameters: {
    msw: {
      handlers: [rest.get('/api/entities/0', (_, res, ctx) => res(ctx.json(ENTITIES[0])))]
    }
  }
};

preview.ts:

initialize({
  onUnhandledRequest: ({ url: { href } }, print) => {
    if (href.includes('use.typekit.net') || href.endsWith('.js')) {
      return;
    }

    print.warning();
  }
});

export const decorators = [
  mswDecorator
];
@peter-oms
Copy link

I've used this with react-query and the same issue occurs when adding ReactQueryDevtools from @tanstack/react-query-devtools to the render tree.

Retriggering a request from the react query dev tools does not get intercepted by MSW.

I think this is an issue with MSW or how it's initialised at least because I tried adding my own decorators as this comment explains and the same happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants