Skip to content

Commit

Permalink
fix(react): Should only add imports for stylesheet that has a style file
Browse files Browse the repository at this point in the history
closes: #28561
  • Loading branch information
ndcunningham committed Nov 1, 2024
1 parent 432a7a8 commit 08906d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import { render } from '@testing-library/react';
<% if (src && !appDir) { %>
<%_ if (src && !appDir) { _%>
import Index from '../src/pages/index';
<% } else if (!appDir) { %>
<%_ } else if (!appDir) { _%>
import Index from '../pages/index';
<% } else if (appDir && src) {%>
<%_ } else if (appDir && src) { _%>
import Page from '../src/app/page';
<% } else { %>
<%_ } else { _%>
import Page from '../app/page';
<% } %>
<%_ } _%>

describe(<%- appDir ? `'Page'` : `'Index'` %>, () => {
it('should render successfully', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<%_ if (strict) { _%>import { StrictMode } from 'react';<%_ } _%>
import * as ReactDOM from 'react-dom/client';
<%_ if (routing) { _%>import { BrowserRouter } from 'react-router-dom';<%_ } _%>

import App from './app/<%= fileName %>';
import './styles.<%= style %>'
<%_ if(hasStyleFile) { _%>
import './styles.<%= style %>'
<%_ } _%>

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
<%_ if(strict && !routing) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function createApplicationFiles(
} else {
styleSolutionSpecificAppFiles = '../files/style-css-module';
}
const hasStyleFile = ['scss', 'css', 'less'].includes(options.style);

const onBoardingStatus = await createNxCloudOnboardingURLForWelcomeApp(
host,
Expand All @@ -64,6 +65,7 @@ export async function createApplicationFiles(
appTests,
inSourceVitestTests: getInSourceVitestTestsTemplate(appTests),
style: options.style === 'tailwind' ? 'css' : options.style,
hasStyleFile,
};

if (options.bundler === 'vite') {
Expand Down

0 comments on commit 08906d2

Please sign in to comment.