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

Improve performance #38

Merged
merged 4 commits into from
Sep 27, 2024
Merged

Conversation

Yama-Tomo
Copy link
Contributor

I was facing the same issue #37 .

Upon investigation, we found that calling createProgram for each HMR was a bottleneck in a project with many module dependencies.
So I thought of replacing createProgram with createWatchProgram to speed up the re-creation of the compiler API on  HMR.

You can apply the following patch to reproduce the issue and test the effect of this fix.
(In version 0.3.1 and later, editing playground/stories/MuiButton.tsx causes lag in HMR.)

Patch for reproduction
diff --git a/playground/package.json b/playground/package.json
index 6ddfa94..2297a83 100644
--- a/playground/package.json
+++ b/playground/package.json
@@ -9,6 +9,9 @@
     "url": "https://github.com/joshwooding/vite-plugin-react-docgen-typescript.git"
   },
   "dependencies": {
+    "@emotion/react": "^11.13.3",
+    "@emotion/styled": "^11.13.0",
+    "@mui/material": "^6.1.1",
     "@storybook/addon-essentials": "7.4.6",
     "@storybook/addon-interactions": "7.4.6",
     "@storybook/addon-links": "7.4.6",
diff --git a/playground/stories/MuiButton.stories.ts b/playground/stories/MuiButton.stories.ts
new file mode 100644
index 0000000..ae20bd1
--- /dev/null
+++ b/playground/stories/MuiButton.stories.ts
@@ -0,0 +1,21 @@
+import type { Meta, StoryObj } from "@storybook/react";
+
+import { MuiButton } from "./MuiButton";
+
+const meta = {
+       title: "Example/MuiButton",
+       component: MuiButton,
+       parameters: {
+               layout: "centered",
+       },
+       tags: ["autodocs"],
+} satisfies Meta<typeof MuiButton>;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+export const Primary: Story = {
+       args: {
+               color: "primary",
+       },
+};
diff --git a/playground/stories/MuiButton.tsx b/playground/stories/MuiButton.tsx
new file mode 100644
index 0000000..07ed1d9
--- /dev/null
+++ b/playground/stories/MuiButton.tsx
@@ -0,0 +1,9 @@
+import React from "react";
+import { Button, ButtonProps } from "@mui/material";
+import lodash from "lodash";
+
+export const MuiButton = (props: ButtonProps) => (
+       <Button {...lodash(props).omit("children").value()}>
+               {lodash(props).pick("children").value().children || "Text!-"}
+       </Button>
+);

Copy link

changeset-bot bot commented Sep 26, 2024

🦋 Changeset detected

Latest commit: 8bc9c78

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@joshwooding/vite-plugin-react-docgen-typescript Patch

Not sure what this means? Click here to learn what changesets are.

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

@joshwooding
Copy link
Owner

Thanks @Yama-Tomo !

@joshwooding joshwooding merged commit 12793a6 into joshwooding:main Sep 27, 2024
1 check passed
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.

2 participants