Skip to content

Moving hook call to another module and importing result breaks RHL #1280

Closed
@rfgamaral

Description

@rfgamaral

Description

I'm using Material-UI and the makeStyles hook to style my application. Everything is working fine when the makeStyles call is in the same file I'll be using it's output. When I place this call in a different file and import the result, RHL breaks.

For instance, take this Application.tsx file:

import React from 'react';

import { hot } from 'react-hot-loader';

import Container from '@material-ui/core/Container';
import CssBaseline from '@material-ui/core/CssBaseline';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';

import { makeStyles } from '@material-ui/core/styles';

interface Props {
    name: string;
}

const useStyles = makeStyles(theme => ({
    container: {
        marginTop: theme.spacing(8)
    },
    paper: {
        padding: theme.spacing(3, 2)
    }
}));

function Application(props: Props): JSX.Element {
    const classes = useStyles();
    const { name } = props;

    return (
      <React.Fragment>
        <CssBaseline />
        <Container className={classes.container} maxWidth="md">
          <Paper className={classes.paper}>
            <Typography variant="h5" component="p" align="center">
              {'Hello there '}
              <span role="img" aria-label="Waving Hand">
                            👋
              </span>
              {`, ${name}`}
            </Typography>
          </Paper>
        </Container>
      </React.Fragment>
    );
}

export default hot(module)(Application);

Note: As you can see I'm using TypeScript with React.

The example above works just fine with RHL, no issues whatsoever.

But now I've changed Application.tsx to this:

import React from 'react';

import { hot } from 'react-hot-loader';

import Container from '@material-ui/core/Container';
import CssBaseline from '@material-ui/core/CssBaseline';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';

import { useStyles } from './Application.styles';

interface Props {
    name: string;
}

function Application(props: Props): JSX.Element {
    const classes = useStyles();
    const { name } = props;

    return (
      <React.Fragment>
        <CssBaseline />
        <Container className={classes.container} maxWidth="md">
          <Paper className={classes.paper}>
            <Typography variant="h5" component="p" align="center">
              {'Hello there '}
              <span role="img" aria-label="Waving Hand">
                            👋
              </span>
              {`, ${name}`}
            </Typography>
          </Paper>
        </Container>
      </React.Fragment>
    );
}

export default hot(module)(Application);

And Application.styles.ts:

import { makeStyles } from '@material-ui/core/styles';

export const useStyles = makeStyles(theme => ({
    container: {
        marginTop: theme.spacing(8),
    },
    paper: {
        padding: theme.spacing(3, 2),
    },
}));

Expected behavior

What you think should happen:

When saving Application.tsx file, RHL should work as expected and without any errors.

Actual behavior

What actually happens:

When saving Application.tsx file, RHL shows this error:

image

Environment

React Hot Loader version: v4.12.0

Run these commands in the project folder and fill in their results:

  1. node -v: v10.15.0
  2. yarn -v: v1.16.0

Then, specify:

  1. Operating system: Windows 10 (WSL)
  2. Browser and version: Firefox Quantum 68.0b14 (64-bit)

Reproducible Demo

I apologize in advanced for not having a demo project yet. If one is really necessary, please let me know and I'll get it pushed as soon as I'm able to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions