next.js icon indicating copy to clipboard operation
next.js copied to clipboard

antd style not load when page change

Open yubaoquan opened this issue 7 years ago • 4 comments

Bug report

Describe the bug

I have two page components PageA and PageB. PageA doesn't use antd components but PageB does. The style file of PageB imported antd's css file: style-b.less

@import '~antd/dist/antd.css';
// ...other styles

PageB:

import './style-b.less'
// ...

When I first open PageB, everything runs well; When I first open PageA and jump to PageB (by click a link in PageA), the antd css file is not loaded.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Open localhost:3000/b (pageB rendered correctly)
  2. Open localhost:3000/a, click the link to jump to b (this time pageB doesn't load antd's style)

Expected behavior

When jump to b from a, b have the antd style file loaded.

System information

  • OS: mac
  • Browser (if applies) chrome 73.0.3683.86
  • Version of Next.js: 8.0.3

yubaoquan avatar Apr 07 '19 17:04 yubaoquan

Maybe this is a duplicate of https://github.com/zeit/next-plugins/issues/1, I'm not sure.

yubaoquan avatar Apr 08 '19 13:04 yubaoquan

Resolved by adding withCSS to now.config.js:

const withTypescript = require('@zeit/next-typescript');
const withCSS = require('@zeit/next-css');
const withLess = require('@zeit/next-less');
const TsConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = withTypescript(withCSS(withLess({
  target: 'serverless',
  webpack(config, options) {
    config.resolve = config.resolve || {};
    config.resolve.plugins = config.resolve.plugins || [];
    config.resolve.plugins.push(new TsConfigPathsPlugin({
      configFile: './tsconfig.json',
    }));

    return config;
  },
})));

yubaoquan avatar Apr 08 '19 13:04 yubaoquan

Resolved by adding withCSS to now.config.js:

const withTypescript = require('@zeit/next-typescript');
const withCSS = require('@zeit/next-css');
const withLess = require('@zeit/next-less');
const TsConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = withTypescript(withCSS(withLess({
  target: 'serverless',
  webpack(config, options) {
    config.resolve = config.resolve || {};
    config.resolve.plugins = config.resolve.plugins || [];
    config.resolve.plugins.push(new TsConfigPathsPlugin({
      configFile: './tsconfig.json',
    }));

    return config;
  },
})));

This solution isn't working for me :(

vishalshettydev avatar Mar 05 '20 10:03 vishalshettydev

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

balazsorban44 avatar Jan 30 '22 11:01 balazsorban44