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

comment boundaries for react refresh transforms #11956

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Sep 4, 2024

to make it easier to read transformed modules in dev

once we switch to better interop with vite-plugin-react this may become obsolete, but until then its nice to have

Example

see the newly added [BEGIN] & [END] comment boundaries below

import { createHotContext as __vite__createHotContext } from "/@vite/client";import.meta.hot = __vite__createHotContext("/app/routes/_index.tsx");

// [BEGIN] REACT REFRESH HEADER ------------------------------------------------
import RefreshRuntime from "/@id/__x00__virtual:react-router/hmr-runtime";

const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
let prevRefreshReg;
let prevRefreshSig;

if (import.meta.hot && !inWebWorker) {
  if (!window.__vite_plugin_react_preamble_installed__) {
    throw new Error(
      "React Router Vite plugin can't detect preamble. Something is wrong."
    );
  }

  prevRefreshReg = window.$RefreshReg$;
  prevRefreshSig = window.$RefreshSig$;
  window.$RefreshReg$ = (type, id) => {
    RefreshRuntime.register(type, "/Users/pedrocattori/remix-run/react-router/playground-local/compiler-1725468106777/app/routes/_index.tsx" + " " + id)
  };
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
}
// [END] REACT REFRESH HEADER --------------------------------------------------

// [BEGIN] REACT REFRESH BODY --------------------------------------------------
import __vite__cjsImport2_react_jsxDevRuntime from "/node_modules/.vite/deps/react_jsx-dev-runtime.js?v=a2c717b5"; const jsxDEV = __vite__cjsImport2_react_jsxDevRuntime["jsxDEV"];
export const meta = () => {
  return [{
    title: "New React Router App"
  }, {
    name: "description",
    content: "Welcome to React Router!"
  }];
};
export default function Index() {
  return /* @__PURE__ */jsxDEV("div", {
    style: {
      fontFamily: "system-ui, sans-serif",
      lineHeight: "1.8"
    },
    children: /* @__PURE__ */jsxDEV("h1", {
      children: "Welcome to React Router"
    }, void 0, false, {
      fileName: "/Users/pedrocattori/remix-run/react-router/playground-local/compiler-1725468106777/app/routes/_index.tsx",
      lineNumber: 13,
      columnNumber: 7
    }, this)
  }, void 0, false, {
    fileName: "/Users/pedrocattori/remix-run/react-router/playground-local/compiler-1725468106777/app/routes/_index.tsx",
    lineNumber: 12,
    columnNumber: 5
  }, this);
}
_c = Index;
var _c;
$RefreshReg$(_c, "Index");
// [END] REACT REFRESH BODY ----------------------------------------------------

// [BEGIN] REACT REFRESH FOOTER ------------------------------------------------
if (import.meta.hot && !inWebWorker) {
  window.$RefreshReg$ = prevRefreshReg;
  window.$RefreshSig$ = prevRefreshSig;
  RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
    RefreshRuntime.registerExportsForReactRefresh("/Users/pedrocattori/remix-run/react-router/playground-local/compiler-1725468106777/app/routes/_index.tsx", currentExports);
    import.meta.hot.accept((nextExports) => {
      if (!nextExports) return;
      "routes/_index" && window.__reactRouterRouteModuleUpdates.set("routes/_index", nextExports);
      const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, ["clientAction","clientLoader","handle","meta","links","shouldRevalidate"]);
      if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
    });
  });
}
// [END] REACT REFRESH FOOTER --------------------------------------------------

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBWU0sU0FBQUEsTUFBQTtBQVZDLGFBQU1DLElBQUEsR0FBcUJBLE1BQU07RUFDdEMsT0FBTyxDQUNMO0lBQUVDLEtBQUEsRUFBTztFQUF1QixHQUNoQztJQUFFQyxJQUFBLEVBQU07SUFBZUMsT0FBQSxFQUFTO0VBQTJCLEVBQzdEO0FBQ0Y7QUFFQSx3QkFBd0JDLFFBQVE7RUFDOUIsT0FDRSxlQUFBTCxNQUFBLENBQUM7SUFBSU0sS0FBQSxFQUFPO01BQU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ZXI8L2gxPlxuICAgIDwvZGl2PlxuICApO1xufVxuIl0sImZpbGUiOiIvVXNlcnMvcGVkcm9jYXR0b3JpL3JlbWl4LXJ1bi9yZWFjdC1yb3V0ZXIvcGxheWdyb3VuZC1sb2NhbC9jb21waWxlci0xNzI1NDY4MTA2Nzc3L2FwcC9yb3V0ZXMvX2luZGV4LnRzeCJ9

to make it easier to read transformed modules in dev
Copy link

changeset-bot bot commented Sep 4, 2024

⚠️ No Changeset found

Latest commit: 14e3626

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pcattori pcattori merged commit 59736e5 into dev Sep 4, 2024
8 checks passed
@pcattori pcattori deleted the pedro/comment-boundaries-for-react-refresh branch September 4, 2024 20:06
REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id))
) +
"\n\n" +
withCommentBoundaries("REACT REFRESH BODY", code) +
Copy link
Member

Choose a reason for hiding this comment

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

Should this one be left off? When reading the compiled source code, typically I'm looking for this bit — it's only the other blocks I'm trying to ignore, which is where the comments are nice.

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 don't feel strongly either way. I thought it was nice to give it a name so there's a ubiquitous language for it when debugging or asking users about it, but if you feel its mostly noise I'm ok with removing it.

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