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

fix(babel): Improved message for error relating to multiple files ending in Page.{js,jsx,ts,tsx} in page directories #9329

Merged
merged 4 commits into from
Oct 23, 2023

Conversation

Josh-Walker-GM
Copy link
Collaborator

@Josh-Walker-GM Josh-Walker-GM commented Oct 22, 2023

Problem
The route auto import babel plugin currently generates duplicate import statements if you have multiple files which end in Page.{js,jsx,ts,tsx} within the same page directory. This causes an error later in the build/dev process. This currently imposes the restriction that only one file end in Page.{js,jsx,ts,tsx} inside the individual page directories.

The error message which you get when this issue occurs is rather obscure and does not easily point users to the source of the problem. This was highlighted in #9165.

The error produced from yarn rw dev without this change:
image

In comparison to after this change:
image

Changes

  1. Checks for duplicate pages as returned from the processPagesDir function and produces a more specific error message in the case where duplicates exist.
  2. Adds a test which covers the case of duplicate files ending in Page.{js,jsx,ts,tsx} within a page directory.

Fixes

Notes

  1. The processPagesDir function is marked as deprecated and is awaiting a new implementation. I did not think doing that now for this issue was wise. I also did not want to alter the logic of that function here as that could introduce side effects of its own.
  2. Happy to change the error message to be even clearer.
  3. We could attempt to trim out the duplicate entries directly where I perform this new check - I'm not against this. I didn't do this immediately because it felt like I would be doing additional work which the processPagesDir function should be doing internally.

@Josh-Walker-GM Josh-Walker-GM added the release:fix This PR is a fix label Oct 22, 2023
@Josh-Walker-GM Josh-Walker-GM added this to the next-release-patch milestone Oct 22, 2023
@Josh-Walker-GM Josh-Walker-GM requested a review from jtoar October 22, 2023 16:28
@Josh-Walker-GM Josh-Walker-GM self-assigned this Oct 22, 2023
Copy link
Contributor

@jtoar jtoar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor comment but works locally and looks good

// ending in Page in the individual page directories. This will cause an error upstream.
// Here we check for duplicates and throw a more helpful error message.
const duplicatePageImports = new Set<string>()
const sortedPageImports = pages.map((page) => page.importName).sort()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggesiton to improve the naming of this variable here cause it's not import statements its just an array of strings like ['AboutPage', 'AboutPage', 'FatalErrorPage']

Suggested change
const sortedPageImports = pages.map((page) => page.importName).sort()
const sortedPageImportNames = pages.map((page) => page.importName).sort()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Updating in ce11673

@Josh-Walker-GM Josh-Walker-GM enabled auto-merge (squash) October 23, 2023 20:26
@Josh-Walker-GM Josh-Walker-GM merged commit 9d4a1e7 into main Oct 23, 2023
@Josh-Walker-GM Josh-Walker-GM deleted the jgmw-fix/9165 branch October 23, 2023 20:50
jtoar pushed a commit that referenced this pull request Nov 2, 2023
…ing in `Page.{js,jsx,ts,tsx}` in page directories (#9329)

**Problem**
The route auto import babel plugin currently generates duplicate import
statements if you have multiple files which end in
`Page.{js,jsx,ts,tsx}` within the same page directory. This causes an
error later in the build/dev process. This currently imposes the
restriction that only one file end in `Page.{js,jsx,ts,tsx}` inside the
individual page directories.

The error message which you get when this issue occurs is rather obscure
and does not easily point users to the source of the problem. This was
highlighted in #9165.

The error produced from `yarn rw dev` without this change:
<img width="931" alt="image"
src="https://github.com/redwoodjs/redwood/assets/56300765/9e7abda6-d42e-477c-8506-b9caea2f1fc8">

In comparison to after this change:
<img width="931" alt="image"
src="https://github.com/redwoodjs/redwood/assets/56300765/964ca266-338d-4fbb-af0f-b75c8f6647ac">

**Changes**
1. Checks for duplicate pages as returned from the `processPagesDir`
function and produces a more specific error message in the case where
duplicates exist.
2. Adds a test which covers the case of duplicate files ending in
`Page.{js,jsx,ts,tsx}` within a page directory.

**Fixes**
* fixes #9165 

**Notes**
1. The `processPagesDir` function is marked as deprecated and is
awaiting a new implementation. I did not think doing that now for this
issue was wise. I also did not want to alter the logic of that function
here as that could introduce side effects of its own.
2. Happy to change the error message to be even clearer.
3. We could attempt to trim out the duplicate entries directly where I
perform this new check - I'm not against this. I didn't do this
immediately because it felt like I would be doing additional work which
the `processPagesDir` function should be doing internally.
jtoar pushed a commit that referenced this pull request Nov 3, 2023
…ing in `Page.{js,jsx,ts,tsx}` in page directories (#9329)

**Problem**
The route auto import babel plugin currently generates duplicate import
statements if you have multiple files which end in
`Page.{js,jsx,ts,tsx}` within the same page directory. This causes an
error later in the build/dev process. This currently imposes the
restriction that only one file end in `Page.{js,jsx,ts,tsx}` inside the
individual page directories.

The error message which you get when this issue occurs is rather obscure
and does not easily point users to the source of the problem. This was
highlighted in #9165.

The error produced from `yarn rw dev` without this change:
<img width="931" alt="image"
src="https://github.com/redwoodjs/redwood/assets/56300765/9e7abda6-d42e-477c-8506-b9caea2f1fc8">

In comparison to after this change:
<img width="931" alt="image"
src="https://github.com/redwoodjs/redwood/assets/56300765/964ca266-338d-4fbb-af0f-b75c8f6647ac">

**Changes**
1. Checks for duplicate pages as returned from the `processPagesDir`
function and produces a more specific error message in the case where
duplicates exist.
2. Adds a test which covers the case of duplicate files ending in
`Page.{js,jsx,ts,tsx}` within a page directory.

**Fixes**
* fixes #9165 

**Notes**
1. The `processPagesDir` function is marked as deprecated and is
awaiting a new implementation. I did not think doing that now for this
issue was wise. I also did not want to alter the logic of that function
here as that could introduce side effects of its own.
2. Happy to change the error message to be even clearer.
3. We could attempt to trim out the duplicate entries directly where I
perform this new check - I'm not against this. I didn't do this
immediately because it felt like I would be doing additional work which
the `processPagesDir` function should be doing internally.
@jtoar jtoar modified the milestones: next-release-patch, v6.3.3 Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug?]: Better error message expected when another file ends with Page.tsx in a page component folder
2 participants