Skip to content

Remove hashes on built filenames #13567

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 10 commits into from
May 16, 2025
Merged

Remove hashes on built filenames #13567

merged 10 commits into from
May 16, 2025

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented May 8, 2025

Only done for the RR package currently but can adopt in the other packages if this is the way to go

I'm pretty sure we got the extracted (and hashed) chunk before because we built index.ts and dom-export.ts in the same config. It then extracted the shared code (all of index.ts) into a chunk.

By giving these to tsup in different configs, it doesn't identify that code as shared and doesn't extract to a chunk. And by marking react-router as external it causes the dom exports to just require/import it correctly and not bundle it.

The output with this config looks like:

packages/react-router/dist/
├── development
│   ├── dom-export.d.mts
│   ├── dom-export.d.ts
│   ├── dom-export.js
│   ├── dom-export.mjs
│   ├── index.d.mts
│   ├── index.d.ts
│   ├── index.js
│   ├── index.mjs
│   ├── internal.d.mts
│   ├── internal.d.ts
│   ├── internal.js
│   └── internal.mjs
└── production
    ├── dom-export.d.mts
    ├── dom-export.d.ts
    ├── dom-export.js
    ├── dom-export.mjs
    ├── index.d.mts
    ├── index.d.ts
    ├── index.js
    ├── index.mjs
    ├── internal.d.mts
    ├── internal.d.ts
    ├── internal.js
    └── internal.mjs

Alternate approach:

I also tried a simpler approach of using splitting: false with external: ['react-router'] (see 7ad3bed) but that still generates some hashed files. However - I don't think we get the typegen E2E test failures with this config so unsure what the difference is there yet.

packages/react-router/dist/
├── development
│   ├── dom-export.d.mts
│   ├── dom-export.d.ts
│   ├── dom-export.js
│   ├── dom-export.mjs
│   ├── index.d.mts
│   ├── index.d.ts
│   ├── index.js
│   ├── index.mjs
│   ├── lib
│   │   └── types
│   │       ├── internal.d.mts
│   │       ├── internal.d.ts
│   │       ├── internal.js
│   │       └── internal.mjs
│   ├── register-BPC2Sp5k.d.mts
│   └── register-BPC2Sp5k.d.ts
└── production
    ├── dom-export.d.mts
    ├── dom-export.d.ts
    ├── dom-export.js
    ├── dom-export.mjs
    ├── index.d.mts
    ├── index.d.ts
    ├── index.js
    ├── index.mjs
    ├── lib
    │   └── types
    │       ├── internal.d.mts
    │       ├── internal.d.ts
    │       ├── internal.js
    │       └── internal.mjs
    ├── register-BPC2Sp5k.d.mts
    └── register-BPC2Sp5k.d.ts

Copy link

changeset-bot bot commented May 8, 2025

🦋 Changeset detected

Latest commit: 893f9cc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
react-router Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brophdawg11 brophdawg11 force-pushed the brophdawg11/build-hashes branch from 8ccf566 to daf7534 Compare May 8, 2025 21:22
Comment on lines 45 to 50
...config("index.ts", false),
...config("index.ts", true),
...config("dom-export.ts", false),
...config("dom-export.ts", true),
...config("lib/types/internal.ts", false),
...config("lib/types/internal.ts", true),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does having separate bundle configs create unique files for each bundle? ie. if two bundles depend on the same source file, does each bundle get its own copy? I remember something like that happening before and unifying the entries into a single config fixed it, but I could be misremembering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does but the external config lets us avoid that. Without external: ['react-router'] it would dup the react router code in index and dom-export, but using that config, dom-export just does import {} from 'react-router' and it resolves through to the index file.

@brophdawg11
Copy link
Contributor Author

@pcattori I think there is still a type issue here from the typegen e2e test, locally it looks like the params weren't resolving right but I'm unsure what about this change would have caused that

@brophdawg11 brophdawg11 force-pushed the brophdawg11/build-hashes branch from d31f45f to d8b4226 Compare May 9, 2025 19:55
@@ -277,7 +277,7 @@ export type {
MiddlewareEnabled as UNSAFE_MiddlewareEnabled,
} from "./lib/types/future.ts";
export type { unstable_SerializesTo } from "./lib/types/serializes-to.ts";
export type { Register } from "./lib/types/register";
export type { Register, Pages, RouteFiles } from "./lib/types/register";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now exported as public API from react-router for consumption by react-router/internal

params: Params<T["file"]>;
loaderData: GetLoaderData<T["module"]>;
actionData: GetActionData<T["module"]>;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lifted to the root to align with our dom-export.ts file

@@ -172,7 +172,7 @@ test.describe("prefetch", () => {
await page.waitForSelector(
// Look for either Rollup or Rolldown chunks
[
"link[rel='modulepreload'][href^='/assets/chunk-']",
"link[rel='modulepreload'][href^='/assets/index-']",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirmed this is just a rename of a dist file but the contents are the same - it's the built file containing react and react router:

# Old:
vite v6.1.1 building for production...
✓ 44 modules transformed.
build/client/.vite/manifest.json                           1.97 kB │ gzip:   0.40 kB
build/client/assets/_index-CIzFY5VO.js                     0.20 kB │ gzip:   0.18 kB
build/client/assets/prefetch-with-loader-DSdeOoqs.js       0.21 kB │ gzip:   0.19 kB
build/client/assets/prefetch-without-loader-RubElpnG.js    0.22 kB │ gzip:   0.19 kB
build/client/assets/with-props-Cx2GuqjJ.js                 0.22 kB │ gzip:   0.19 kB
build/client/assets/root-BX6sQn4U.js                       0.73 kB │ gzip:   0.38 kB
build/client/assets/chunk-23TDSFDP-DRRB-IEc.js           131.31 kB │ gzip:  43.82 kB 👈
build/client/assets/entry.client-Dsu8FA8V.js             339.28 kB │ gzip: 101.90 kB

# New
vite v6.1.1 building for production...
✓ 43 modules transformed.
build/client/.vite/manifest.json                           1.89 kB │ gzip:   0.38 kB
build/client/assets/_index-P-ZakiLo.js                     0.19 kB │ gzip:   0.17 kB
build/client/assets/prefetch-with-loader-COazqWjd.js       0.20 kB │ gzip:   0.18 kB
build/client/assets/prefetch-without-loader-CD33gy26.js    0.21 kB │ gzip:   0.18 kB
build/client/assets/with-props-06UYi0rd.js                 0.21 kB │ gzip:   0.18 kB
build/client/assets/root-C717KEjd.js                       0.72 kB │ gzip:   0.37 kB
build/client/assets/index-DRRB-IEc.js                    131.31 kB │ gzip:  43.82 kB 👈
build/client/assets/entry.client-B9qJACK4.js             339.27 kB │ gzip: 101.88 kB

@@ -94,7 +94,7 @@ import {
useResolvedPath,
useRouteId,
} from "../hooks";
import type { SerializeFrom } from "../types/route-data";
import type { SerializeFrom } from "../types/internal-export/route-data";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pcattori It looks like we have some circular deps here which are probably fine but it might be something we look into cleaning up later? react-router/internal imports RouteFiles from react-router so it doesn't seem like react-router should reach back into /internal stuff?

It looks like the underlying shared thing is ServerDataFrom/ClientDataFrom so maybe they should be exported as UNSAFE_ from react-router and pulled into /internal that way alongside RouteFiles?

@@ -1,12 +1,12 @@
import type {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything directly exported from internal-export.ts now lives in the types/internal-export/ folder

@brophdawg11 brophdawg11 marked this pull request as ready for review May 15, 2025 15:36
@brophdawg11 brophdawg11 changed the title POC to remove hashes on built filenames Remove hashes on built filenames May 16, 2025
@brophdawg11 brophdawg11 merged commit a105445 into dev May 16, 2025
8 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/build-hashes branch May 16, 2025 13:37
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-30460939b-20250517 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

brophdawg11 added a commit that referenced this pull request May 20, 2025
brophdawg11 added a commit that referenced this pull request May 24, 2025
Copy link
Contributor

🤖 Hello there,

We just published version 7.6.1 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants