Skip to content

Use a more appropriate regexp for removing hash from a filename #4510

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

Merged
merged 2 commits into from
Jun 7, 2018

Conversation

fatfisz
Copy link
Contributor

@fatfisz fatfisz commented Jun 1, 2018

Fixes one of the problems described in #4433.

The old regexp was removing everything after a hyphen, so with a chunk name like so:

chunks/path-to-a-file-[hash].js

the saved chunk name was

chunks/path

This caused problems, because webpack by default changes / to - in chunk names generated e.g. by import(`foo/${bar}`).

After this change the chunk name will be

chunks/path-to-a-file

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

Cool 👍

@timneutkens timneutkens merged commit e6ff476 into vercel:canary Jun 7, 2018
@fatfisz fatfisz deleted the available-chunks-regex-fix branch June 7, 2018 20:27
timneutkens pushed a commit that referenced this pull request Jun 9, 2018
This fixes a missed bug introduced in #4510.

Because the regexp was `/-[^-]*/` and not `/-[^-]*$/`, a wrong part of the filename was being removed:

```
bad:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-0123456789abcdef-0123456789abcdef.js'

good:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-bar-0123456789abcdef'
```

By a stroke of luck this didn't affect the existing dynamically generated chunks. To prevent regression I've added unit tests for the function that generates the name.

Btw. in the original issue (#4433) I used the right regexp, I just used the wrong regexp in #4510.

cc @timneutkens
lependu pushed a commit to lependu/next.js that referenced this pull request Jun 19, 2018
…el#4510)

Fixes one of the problems described in vercel#4433.

The old regexp was removing everything after a hyphen, so with a chunk name like so:

```
chunks/path-to-a-file-[hash].js
```

the saved chunk name was

```
chunks/path
```

This caused problems, because webpack by default changes `/` to `-` in chunk names generated e.g. by ``import(`foo/${bar}`)``.

After this change the chunk name will be

```
chunks/path-to-a-file
```
lependu pushed a commit to lependu/next.js that referenced this pull request Jun 19, 2018
This fixes a missed bug introduced in vercel#4510.

Because the regexp was `/-[^-]*/` and not `/-[^-]*$/`, a wrong part of the filename was being removed:

```
bad:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-0123456789abcdef-0123456789abcdef.js'

good:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-bar-0123456789abcdef'
```

By a stroke of luck this didn't affect the existing dynamically generated chunks. To prevent regression I've added unit tests for the function that generates the name.

Btw. in the original issue (vercel#4433) I used the right regexp, I just used the wrong regexp in vercel#4510.

cc @timneutkens
@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants