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

feat: source maps #1609

Merged
merged 9 commits into from
Jan 21, 2025
Merged

feat: source maps #1609

merged 9 commits into from
Jan 21, 2025

Conversation

asvishnyakov
Copy link
Contributor

This PR adds source map support to the Chainlit frontend and the react-client library.

Source maps make debugging easier, particularly in production environments. They allow you to debug pre-compiled code without needing to deploy a debug version or run Chainlit from the source code.

This PR enables source map generation as separate files, ensuring it does not affect the resulting bundle, package, or wheel size, except for a single line added at the end of each file to reference the corresponding source map file.

You can learn more about source maps here and the settings used here and here.

After this PR, the build system may generate numerous warnings about missing source maps and incorrectly (though this doesn't seem to have much impact) add the source map link to files twice, with the wrong file name the first time (out.js.map instead of index.js.map).

The first issue can be resolved by upgrading to vite-plugin-react-swc version 3.7.1 or later, and the second by upgrading tsup to version 8.1.2 or later.

Unfortunately, I wasn't able to get source maps working for libs/* when they are included in the frontend app compiled in production mode. This seems to be an issue with Vite/React/SWC, as it affects all dependencies, not just libs/*. However, source maps for libs/* are generated correctly and can be used in other apps that depend on these libraries.

Feel free to edit this PR if needed as I allowed edits by maintainers.

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. frontend Pertains to the frontend. labels Dec 25, 2024
@willydouhard
Copy link
Collaborator

Thank you for the contribution! Is this impacting the bundle size?

@asvishnyakov
Copy link
Contributor Author

asvishnyakov commented Jan 16, 2025

@willydouhard It depends on what you mean by bundle size. The bundle itself (i.e., the size of index.js) will remain the same (except single additional line with source map file name at the end), and end users will not notice any change in the overall size of loaded files in the browser. However, the zip file (npm or pip wheel) containing it will include an additional large file, and developers who open the browser's developer console will load this additional data.

@dokterbob dokterbob enabled auto-merge (squash) January 20, 2025 16:09
Copy link
Collaborator

@dokterbob dokterbob left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@dokterbob dokterbob merged commit acec473 into Chainlit:main Jan 21, 2025
9 checks passed
@asvishnyakov asvishnyakov deleted the source-maps branch January 22, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Pertains to the frontend. size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants