Skip to content

fix(rsc): fix internal import to allow stable react vendor chunk#824

Merged
hi-ogawa merged 6 commits into
mainfrom
05-09-chore_react_vendor_chunk_in_example
Jun 12, 2025
Merged

fix(rsc): fix internal import to allow stable react vendor chunk#824
hi-ogawa merged 6 commits into
mainfrom
05-09-chore_react_vendor_chunk_in_example

Conversation

@hi-ogawa
Copy link
Copy Markdown
Owner

@hi-ogawa hi-ogawa commented May 9, 2025

Just curiosity. I was wondering what would be a Vite equivalent of https://github.com/web-infra-dev/rsbuild/blob/main/packages/plugin-react/src/splitChunks.ts

Testing manualChunks is postponed for #940 for now since that's going to be tricky for rolldown-vite ci.

Copy link
Copy Markdown
Owner Author

hi-ogawa commented May 9, 2025

@hi-ogawa hi-ogawa force-pushed the 05-09-chore_react_vendor_chunk_in_example branch from 78213b0 to 439d66d Compare May 9, 2025 01:25
@hi-ogawa hi-ogawa force-pushed the 05-09-chore_react_vendor_chunk_in_example branch from 439d66d to a529eaa Compare June 12, 2025 03:24
const name = this.environment.name === "client" ? "browser" : "ssr";
output.prepend(
`import * as $$ReactClient from "${PKG_NAME}/${name}";\n`,
`import * as $$ReactClient from "${PKG_NAME}/react/${name}";\n`,
Copy link
Copy Markdown
Owner Author

@hi-ogawa hi-ogawa Jun 12, 2025

Choose a reason for hiding this comment

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

This is crucial to have createServerReference etc... to be included in react vendor chunk e.g.

import { g as createServerReference, h as callServer, i as findSourceMapURL, j as jsxRuntimeExports, R as React } from "./lib-react-Ck-kPwtf.js";
const testAction = /* @__PURE__ */ createServerReference("fc50c6581262#testAction", callServer, void 0, findSourceMapURL, "testAction");
const testAction2 = /* @__PURE__ */ createServerReference("fc50c6581262#testAction2", callServer, void 0, findSourceMapURL, "testAction2");
const testActionState = /* @__PURE__ */ createServerReference("fc50c6581262#testActionState", callServer, void 0, findSourceMapURL, "testActionState");
function TestActionFromClient() {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { action: testAction, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("button", { children: "test-action-from-client" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("button", { formAction: testAction2, children: "test-action-from-client-2" })
  ] });
}
function TestUseActionState() {
  const [state, formAction] = React.useActionState(testActionState, 0);
  return /* @__PURE__ */ jsxRuntimeExports.jsx("form", { action: formAction, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { "data-testid": "use-action-state", children: [
    "test-useActionState: ",
    state
  ] }) });
}
export {
  TestActionFromClient,
  TestUseActionState
};

We cannot put @hiogawa/vite-rsc/browser in vendor chunk because that includes whole virtual modules etc... internals.

@hi-ogawa hi-ogawa force-pushed the 05-09-chore_react_vendor_chunk_in_example branch from a529eaa to 9119d00 Compare June 12, 2025 04:47
@hi-ogawa hi-ogawa mentioned this pull request Jun 12, 2025
@hi-ogawa hi-ogawa force-pushed the 05-09-chore_react_vendor_chunk_in_example branch from 9119d00 to 7ce3017 Compare June 12, 2025 05:07
@hi-ogawa hi-ogawa changed the title chore: react vendor chunk in example fix(rsc): change internal import to allow stable react vendor chunk Jun 12, 2025
@hi-ogawa hi-ogawa changed the title fix(rsc): change internal import to allow stable react vendor chunk fix(rsc): fix internal import to allow stable react vendor chunk Jun 12, 2025
@hi-ogawa hi-ogawa changed the title fix(rsc): fix internal import to allow stable react vendor chunk fix(rsc): fix internal import to allow stable client reference chunk Jun 12, 2025
@hi-ogawa hi-ogawa changed the title fix(rsc): fix internal import to allow stable client reference chunk fix(rsc): fix internal import to allow stable react vendor chunk Jun 12, 2025
@hi-ogawa hi-ogawa marked this pull request as ready for review June 12, 2025 05:24
@hi-ogawa hi-ogawa force-pushed the 05-09-chore_react_vendor_chunk_in_example branch from d2d8a0e to e5a7f8a Compare June 12, 2025 05:42
@hi-ogawa hi-ogawa marked this pull request as draft June 12, 2025 05:53
@hi-ogawa hi-ogawa marked this pull request as ready for review June 12, 2025 07:15
@hi-ogawa hi-ogawa force-pushed the 05-09-chore_react_vendor_chunk_in_example branch from e5a7f8a to 2eab0c8 Compare June 12, 2025 07:17
Copy link
Copy Markdown
Owner Author

hi-ogawa commented Jun 12, 2025

Merge activity

  • Jun 12, 7:25 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 12, 7:26 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 12, 7:32 AM UTC: @hi-ogawa merged this pull request with Graphite.

@hi-ogawa hi-ogawa force-pushed the 05-09-chore_react_vendor_chunk_in_example branch from 2eab0c8 to a0fa557 Compare June 12, 2025 07:26
@hi-ogawa hi-ogawa merged commit 4c3b548 into main Jun 12, 2025
14 checks passed
@hi-ogawa hi-ogawa deleted the 05-09-chore_react_vendor_chunk_in_example branch June 12, 2025 07:32
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.

1 participant