-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve overrides bundle size (#2186)
## What's the purpose of this pull request? This PR improves the performance of the Section Override API. ## How it works? It works by removing the centralized imports where an object would contain the components for all of the sections. This made the sections and default components to be imported even where they were not used, making the bundle to be bigger than necessary. It also introduces a breaking change to the previously proposed API: instead of providing the name of the section to be overridden, users should provide the section itself. ```tsx import { Alert, getOverriddenSection } from "@faststore/core"; const NewAlert = getOverriddenSection({ Section: Alert, components: {} }); export default NewAlert; ``` ## How to test it? Use this version of the package on the starter and try to create overrides for the supported V2 sections!
- Loading branch information
Ícaro Azevedo
authored
Jan 8, 2024
1 parent
f3b56c7
commit 7a46e5e
Showing
29 changed files
with
536 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
packages/core/src/components/sections/Alert/OverriddenDefaultAlert.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { override } from 'src/customizations/src/components/overrides/Alert' | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition' | ||
import Alert from '.' | ||
|
||
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition' | ||
|
||
/** | ||
* This component exists to support overrides 1.0 | ||
* | ||
* This allows users to override the default Alert section present in the Headless CMS | ||
*/ | ||
export const OverriddenDefaultAlert = getOverriddenSection( | ||
override as SectionOverrideDefinition<'Alert'> | ||
) | ||
export const OverriddenDefaultAlert = getOverriddenSection({ | ||
...(override as SectionOverrideDefinitionV1<'Alert'>), | ||
Section: Alert, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
packages/core/src/components/sections/BannerText/OverriddenDefaultBannerText.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { override } from 'src/customizations/src/components/overrides/BannerText' | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition' | ||
import BannerText from '.' | ||
|
||
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition' | ||
|
||
/** | ||
* This component exists to support overrides 1.0 | ||
* | ||
* This allows users to override the default BannerText section present in the Headless CMS | ||
*/ | ||
export const OverriddenDefaultBannerText = getOverriddenSection( | ||
override as SectionOverrideDefinition<'BannerText'> | ||
) | ||
export const OverriddenDefaultBannerText = getOverriddenSection({ | ||
...(override as SectionOverrideDefinitionV1<'BannerText'>), | ||
Section: BannerText, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
packages/core/src/components/sections/Breadcrumb/OverriddenDefaultBreadcrumb.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { override } from 'src/customizations/src/components/overrides/Breadcrumb' | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition' | ||
import Breadcrumb from '.' | ||
|
||
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition' | ||
|
||
/** | ||
* This component exists to support overrides 1.0 | ||
* | ||
* This allows users to override the default Breadcrumb section present in the Headless CMS | ||
*/ | ||
export const OverriddenDefaultBreadcrumb = getOverriddenSection( | ||
override as SectionOverrideDefinition<'Breadcrumb'> | ||
) | ||
export const OverriddenDefaultBreadcrumb = getOverriddenSection({ | ||
...(override as SectionOverrideDefinitionV1<'Breadcrumb'>), | ||
Section: Breadcrumb, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ages/core/src/components/sections/CrossSellingShelf/OverriddenDefaultCrossSellingShelf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import CrossSellingShelf from '.' | ||
|
||
export const OverriddenDefaultCrossSellingShelf = getOverriddenSection({ | ||
section: 'CrossSellingShelf', | ||
Section: CrossSellingShelf, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
packages/core/src/components/sections/Hero/OverriddenDefaultHero.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { override } from 'src/customizations/src/components/overrides/Hero' | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition' | ||
import Hero from '.' | ||
|
||
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition' | ||
|
||
/** | ||
* This component exists to support overrides 1.0 | ||
* | ||
* This allows users to override the default Hero section present in the Headless CMS | ||
*/ | ||
export const OverriddenDefaultHero = getOverriddenSection( | ||
override as SectionOverrideDefinition<'Hero'> | ||
) | ||
export const OverriddenDefaultHero = getOverriddenSection({ | ||
...(override as SectionOverrideDefinitionV1<'Hero'>), | ||
Section: Hero, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
packages/core/src/components/sections/Navbar/OverriddenDefaultNavbar.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { override } from 'src/customizations/src/components/overrides/Navbar' | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition' | ||
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition' | ||
import Navbar from './Navbar' | ||
|
||
/** | ||
* This component exists to support overrides 1.0 | ||
* | ||
* This allows users to override the default Navbar section present in the Headless CMS | ||
*/ | ||
export const OverriddenDefaultNavbar = getOverriddenSection( | ||
override as SectionOverrideDefinition<'Navbar'> | ||
) | ||
export const OverriddenDefaultNavbar = getOverriddenSection({ | ||
...(override as SectionOverrideDefinitionV1<'Navbar'>), | ||
Section: Navbar, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
packages/core/src/components/sections/Newsletter/OverriddenDefaultNewsletter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { override } from 'src/customizations/src/components/overrides/Newsletter' | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition' | ||
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition' | ||
import Newsletter from './Newsletter' | ||
|
||
/** | ||
* This component exists to support overrides 1.0 | ||
* | ||
* This allows users to override the default Newsletter section present in the Headless CMS | ||
*/ | ||
export const OverriddenDefaultNewsletter = getOverriddenSection( | ||
override as SectionOverrideDefinition<'Newsletter'> | ||
) | ||
export const OverriddenDefaultNewsletter = getOverriddenSection({ | ||
...(override as SectionOverrideDefinitionV1<'Newsletter'>), | ||
Section: Newsletter, | ||
}) |
11 changes: 7 additions & 4 deletions
11
packages/core/src/components/sections/ProductDetails/OverriddenDefaultProductDetails.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { override } from 'src/customizations/src/components/overrides/ProductDetails' | ||
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection' | ||
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition' | ||
import ProductDetails from './ProductDetails' | ||
|
||
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition' | ||
|
||
/** | ||
* This component exists to support overrides 1.0 | ||
* | ||
* This allows users to override the default ProductDetails section present in the Headless CMS | ||
*/ | ||
export const OverriddenDefaultProductDetails = getOverriddenSection( | ||
override as SectionOverrideDefinition<'ProductDetails'> | ||
) | ||
export const OverriddenDefaultProductDetails = getOverriddenSection({ | ||
...(override as SectionOverrideDefinitionV1<'ProductDetails'>), | ||
Section: ProductDetails, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.