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 bundle size with reader API in React server component environments #618

Merged
merged 8 commits into from
Sep 5, 2023

Conversation

emmatown
Copy link
Member

@emmatown emmatown commented Sep 5, 2023

Fixes #453
Fixes #601

This replaces 'use client's in UI modules imported by code that's needed for the reader API with using the package.json#imports field to map those UI modules to empty implementations in react-server environments so that Next will never bundle those UI modules into pages using the reader API

As an example of the improvement, in the dev-projects/next-app, using the reader API made the first load JS 600 kB, after these changes, it's 77.7 kB which seems to be the baseline with Next. (testing with the custom Note component block that's there disabled in both cases)

@vercel
Copy link

vercel bot commented Sep 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
keystar-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 5, 2023 5:26am
keystatic ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 5, 2023 5:26am
keystatic-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 5, 2023 5:26am

@changeset-bot
Copy link

changeset-bot bot commented Sep 5, 2023

🦋 Changeset detected

Latest commit: 35ff750

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

This PR includes changesets to release 1 package
Name Type
@keystatic/core 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

"react-server": "./src/form/fields/document/DocumentEditor/primitives/blank-for-react-server.tsx",
"default": "./src/form/fields/document/DocumentEditor/primitives/index.tsx"
},
"#cloud-image-preview": {
Copy link
Member

Choose a reason for hiding this comment

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

this feels ... moderately unsustainable, if we end up with many more component blocks? could/should we organise this differently, like have an component-blocks import? or is this just private API and it doesn't matter, we can refactor it later if that's an issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

is this just private API and it doesn't matter, we can refactor it later if that's an issue?

This, all of the imports field is entirely private

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants