Skip to content

Conversation

@markerikson
Copy link
Collaborator

@markerikson markerikson commented Nov 3, 2025

This PR byte-shaves a variety of repeated bits of code I saw:

  • Rewrote setupListeners to reuse event names and deduplicate window.addEventListener
  • Found out that ESBuild auto-inlines TS enums, so that our checks like status === QueryStatus.initialized were getting rewritten to === "initialized" every time. The TS enum got runtime-compiled, but was unused. Added equivalent string constants, so the enum is now used for type-checks, but the constants are used for runtime comparisons.
  • Consolidated all third-party imports into reusable modules, as ESBuild does not deduplicate imports when it bundles, leading to multiple imports from the same package and renamed imports. I had done this previously for RTK into RTKQ, but now done for other modules too.
  • Added some wrappers for common lookup patterns (context.endpointDefinitions[endpointName], some action meta fields, promise ref unsubscribes)

This looks like it knocks about 600 bytes minified off of the RTKQ core artifact, and another 200 bytes off of the RTKQ React artifact:

image

@codesandbox
Copy link

codesandbox bot commented Nov 3, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 3, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7891846:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

size-limit report 📦

Path Size
1. entry point: @reduxjs/toolkit/query/react (modern.mjs) 15.42 KB (+0.45% 🔺)
1. entry point: @reduxjs/toolkit (cjs, production.min.cjs) 0 B (-100% 🔽)
1. entry point: @reduxjs/toolkit/react (cjs, production.min.cjs) 0 B (-100% 🔽)
1. entry point: @reduxjs/toolkit/query (cjs, production.min.cjs) 0 B (-100% 🔽)
1. entry point: @reduxjs/toolkit/query/react (cjs, production.min.cjs) 0 B (-100% 🔽)
2. entry point: @reduxjs/toolkit (without dependencies) (cjs, production.min.cjs) 0 B (-100% 🔽)
2. entry point: @reduxjs/toolkit/react (without dependencies) (cjs, production.min.cjs) 0 B (-100% 🔽)
2. entry point: @reduxjs/toolkit/query (without dependencies) (cjs, production.min.cjs) 0 B (-100% 🔽)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (cjs, production.min.cjs) 0 B (-100% 🔽)
3. createApi (.modern.mjs) 15.82 KB (+0.3% 🔺)
3. createApi (react) (.modern.mjs) 17.83 KB (-0.02% 🔽)
1. entry point: @reduxjs/toolkit (browser.mjs) 5.2 KB (+100% 🔺)
1. entry point: @reduxjs/toolkit/react (browser.mjs) 28 B (+100% 🔺)
1. entry point: @reduxjs/toolkit/query (browser.mjs) 6.04 KB (+100% 🔺)
1. entry point: @reduxjs/toolkit/query/react (browser.mjs) 18.38 KB (+100% 🔺)
2. entry point: @reduxjs/toolkit (without dependencies) (browser.mjs) 1.7 KB (+100% 🔺)
2. entry point: @reduxjs/toolkit/react (without dependencies) (browser.mjs) 28 B (+100% 🔺)
2. entry point: @reduxjs/toolkit/query (without dependencies) (browser.mjs) 765 B (+100% 🔺)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (browser.mjs) 2.45 KB (+100% 🔺)

@netlify
Copy link

netlify bot commented Nov 3, 2025

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit 7891846
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/690845f19ca04d0008ca91bc
😎 Deploy Preview https://deploy-preview-5129--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@markerikson
Copy link
Collaborator Author

markerikson commented Nov 3, 2025

Eh, messing with size-limit borked the comment comparisons for this PR. Ah well. I can see it's an improvement anyway :)

Confirmed using some Sonda analysis in an actual Vite app example that this knocks about 0.6K off the final app size.

@markerikson markerikson merged commit 9aae695 into master Nov 3, 2025
120 checks passed
@aryaemami59 aryaemami59 deleted the feature/byteshave-fields branch November 3, 2025 06:33
Copy link

@glepretre glepretre left a comment

Choose a reason for hiding this comment

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

false,
)
window.addEventListener('focus', handleFocus, false)
const WINDOW = window

Choose a reason for hiding this comment

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

We lost the SSR support here in v2.10.0

UnhandledRejection ReferenceError: window is not defined
    at defaultHandler (file:///node_modules/@reduxjs/toolkit/dist/query/rtk-query.modern.mjs:417:22

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants