Skip to content

Better tree-shakeability, React 19, typed JSX-components #2052

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

Merged
merged 62 commits into from
Mar 28, 2025

Conversation

splashdust
Copy link
Contributor

@splashdust splashdust commented Mar 14, 2025

This PR bumps React to version 19 for the mono repo. This means that tests and builds of the React library will run against v19 going forward.

There are also a few other changes included, aimed to improve developer experience:

"Batteries included" for React:

Since React 19 natively supports custom elements, we can export typed JSX components from the Core library instead of relying on Lits custom element wrapper. This means that it will no longer be necessary to create local wrappers for React. Instead components can just be imported from @sebgroup/green-core/react:

import { GdsButton } from '@sebgroup/green-core/react'

<GdsButton rank="secondary" onClick={() => console.log('Hello')}>Click me!</GdsButton>

Move towards tree-shakeable components:

This changes the way components are defined in the custom elements registry. Previously it was only possible to import components with the define step was a mandatory side-effect. This meant that bundles could not remove any Green Core components, even if they were not used or referenced.

In this PR, an alternative, side-effect free, way of importing components has been added. Each component now has a file called [name].component.ts which holds the actual implementation, but does not define the custom element. Each component class now also has a static method called define() which can be used to define the element. The old [name].ts module will still call the define step, so existing code should remain unaffected.

All the side-effect free components are then bulk exported from @sebgroup/green-core/pure so that imports can be grouped.

Here is how to use the new side-effect free imports:

// This imports the component classes with no side-effects
import { GdsButton, GdsDropdown } from '@sebgroup/green-core/pure'

// This is required before the components can be used. This call defines the element in the
// custom elements registry.
GdsButton.define()
GdsDropdown.define()

For screnarios where bundle size is irrelevant, all components (including icons) can be imported from @sebgroup/green-core/everything. Use with caution, as this will inflate your bundle size with ~600kb:

import "@sebgroup/green-core/everything"

@green-design-system-bot
Copy link
Contributor

green-design-system-bot bot commented Mar 14, 2025

🦋 Changeset status

Based on the included changeset, the following releases will be published as a result of this PR:

  • @sebgroup/green-core: 1.69.4 → 1.70.0 (minor bump)
  • @sebgroup/green-angular: 5.6.0 → 5.6.1 (patch bump)
  • @sebgroup/green-react: 3.25.0 → 3.26.0 (minor bump)

Note: If unpublished changesets where merged to main after the first commit of this PR, this
list will include those changes in addition to the ones specific to this PR.

@splashdust splashdust changed the title Green React: Upgrade to React 19 Btter tree-shakeability, React 19, typed JSX-components Mar 18, 2025
@splashdust splashdust changed the title Btter tree-shakeability, React 19, typed JSX-components Better tree-shakeability, React 19, typed JSX-components Mar 18, 2025
@splashdust splashdust marked this pull request as ready for review March 28, 2025 10:05
@splashdust splashdust requested a review from Copilot March 28, 2025 10:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR upgrades React to v19 and introduces tree-shakeable, typed JSX components that improve developer ergonomics. Key changes include bumping to React 19, exporting direct JSX component wrappers from the Core library, and providing a side-effect free way to use components via pure imports.

Reviewed Changes

Copilot reviewed 957 out of 959 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
apps/react-lib-dev/src/design/blocks/sidebar.tsx Introduces the Sidebar component with routing and layout changes.
apps/react-lib-dev/src/design/blocks/header.tsx Implements the Header component with a responsive menu toggle.
apps/react-lib-dev/src/config/routes.tsx Defines the new route configuration with nested subRoutes.
apps/react-lib-dev/src/components/green-core-form.tsx Updates the form example to use new JSX wrappers and a dynamic field reflection.
apps/react-lib-dev/src/app/app.tsx Refactors the App component to integrate the new Header/Sidebar layout and dynamic route rendering.
apps/docs/utils/import/components.tsx Switches from dynamic imports to static re-exports from the new Core react package.
apps/docs/app/layout.tsx Wraps the layout in the new theme component to enforce the design version.
.changeset/* Updates documenting the React 19 upgrade and treeshaking improvements.
Files not reviewed (2)
  • apps/docs/tsconfig.json: Language not supported
  • apps/react-lib-dev/project.json: Language not supported
Comments suppressed due to low confidence (1)

apps/react-lib-dev/src/components/green-core-form.tsx:231

  • The component 'CoreFlex' is used without an explicit import; please ensure that it is properly imported to avoid runtime errors.
<CoreFlex align-items="center" gap="m">

@splashdust splashdust requested review from astrit and vsjolander March 28, 2025 10:13
Copy link
Member

@astrit astrit left a comment

Choose a reason for hiding this comment

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

Looks good to me, tremendous amount of work here very excited to upgrade docs to latest version 👌

@splashdust splashdust merged commit 0e6d189 into main Mar 28, 2025
5 checks passed
@splashdust splashdust deleted the chore/react-19 branch March 28, 2025 14:53
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