Skip to content

Commit

Permalink
fix(nextjs): Formatting for pages (#28734)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #28561
  • Loading branch information
ndcunningham authored Nov 1, 2024
1 parent 9a88ea8 commit 0706c7f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
27 changes: 12 additions & 15 deletions packages/next/src/generators/application/files/app/page.tsx__tmpl__
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<% if (style !== 'none') { %>
<% if (styledModule && (styledModule === 'styled-jsx' || styledModule === 'styled-components')) {%>
'use client';
<% }%>
<% if (styledModule && styledModule !== 'styled-jsx') {
var wrapper = 'StyledPage';
%>import styled from '<%= styledModule %>';<% } else {
var wrapper = 'div';
%>
<%- (style !== 'styled-jsx' && style !== 'tailwind') ? `import styles from './page.module.${style}';` : '' %>
<% }
%>
<%_ if (style !== 'none') { _%>
<%_ if (styledModule && (styledModule === 'styled-jsx' || styledModule === 'styled-components')) { _%>
'use client';
<%_ } _%>
<%_ if (styledModule && styledModule !== 'styled-jsx') { var wrapper = 'StyledPage'; _%>
import styled from '<%= styledModule %>';
<%_ } else { var wrapper = 'div'; _%>
<%- (style !== 'styled-jsx' && style !== 'tailwind') ? `import styles from './page.module.${style}';` : '' %>
<%_ } _%>

<% if (styledModule && styledModule !== 'styled-jsx') { %>
const StyledPage = styled.div`<%- pageStyleContent %>`;
<% }%>
<%_ if (styledModule && styledModule !== 'styled-jsx') { _%>
const StyledPage = styled.div`<%- pageStyleContent %>`;
<%_ } _%>
<% } %>
export default function Index() {
/*
Expand Down
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,17 +1,14 @@
<% if (style !== 'none') { %>
<% if (styledModule && styledModule !== 'styled-jsx') {
var wrapper = 'StyledPage';
%>import styled from '<%= styledModule %>';<% } else {
var wrapper = 'div';
%>
<%- (style !== 'styled-jsx' && style !== 'tailwind') ? `import styles from './${fileName}.module.${style}';` : '' %>
<% }
%>
<%_ if (style !== 'none') { _%>
<%_ if (styledModule && styledModule !== 'styled-jsx') { var wrapper = 'StyledPage'; _%>
import styled from '<%= styledModule %>';
<% } else { var wrapper = 'div';%>
<%- (style !== 'styled-jsx' && style !== 'tailwind') ? `import styles from './${fileName}.module.${style}';` : '' %>
<%_ } _%>

<% if (styledModule && styledModule !== 'styled-jsx') { %>
const StyledPage = styled.div`<%- pageStyleContent %>`;
<% }%>
<% } %>
<%_ if (styledModule && styledModule !== 'styled-jsx') { _%>
const StyledPage = styled.div`<%- pageStyleContent %>`;
<%_ } _%>
<%_ } _%>

export function Index() {
/*
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 0706c7f

Please sign in to comment.