fix: Add browser field in package.json so react-dom/server stays out of browser bundles#343
Open
smeng9 wants to merge 1 commit into
Open
fix: Add browser field in package.json so react-dom/server stays out of browser bundles#343smeng9 wants to merge 1 commit into
smeng9 wants to merge 1 commit into
Conversation
…bundles
The npm entry (dist/index.js) externalizes node_modules, so the lazy
require("react-dom/server") in Viewer.renderToString survived into the shipped
bundle. Any bundler resolving seqviz via main was then forced to resolve
react-dom/server, pulling Node-only SSR code into browser bundles (Lattice-Automation#293).
- Extract shared render/setState logic into src/baseViewer.ts (createBaseViewer;
imports only react + react-dom/client, never react-dom/server).
- Rebuild the node entry (src/index.ts) on the shared core, keeping the lazy
require("react-dom/server") for renderToString. Output behavior unchanged.
- Add src/index.browser.ts: same exports, but Viewer returns only
{ render, setState } and has no path to react-dom/server.
- webpack: rename npmBuild -> nodeBuild, add browserBuild -> dist/index.browser.js.
- package.json: add browser field + exports map with per-condition types
(browser -> dist/index.browser.d.ts, no renderToString). Legacy main/browser/
types/unpkg fields retained; ./dist/* keeps deep imports working.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
Additionally we can consider just reexporting the React components, and dropping the Viewer function in the browser build |
Collaborator
|
@jjti any thoughts on this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #293
Replaces: #294
With the fix in #294 we still encounter issues in module-federation, and module-federation loader crashes because it cannot provide
react-dom/serverin the browser.Module federation's remote build will try to hoist all reqire() dependencies in the code, (regardless of lazy or not, see https://npmx.dev/package-code/seqviz/v/3.10.22/dist%2Findex.js#L7137) and we shouldn't include the SSR
react-dom/serverin the browser build.It is better to create a browser only build with no react-dom/server following the option B in #293