consolidated react provider#1259
Draft
tenub wants to merge 21 commits into
Draft
Conversation
7756c68 to
576dd3b
Compare
|
🚀 Components Preview Deployed! 📍 Preview URL: https://schematic-next-example-nczm0mri2-schematichq.vercel.app |
Reverts the removal of components/ and its CI from the prior cleanup commit, while preserving the react2/ → react/ rename. The standalone components/ package continues to ship for existing consumers; new code should prefer the unified react/ package's /components subpath. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
🚀 Components Preview Deployed! 📍 Preview URL: https://schematic-next-example-iva6msjhn-schematichq.vercel.app |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consolidates the legacy
@schematichq/schematic-react(WS-backed flags/entitlements) and@schematichq/schematic-components(REST-backed UI) into a single package with subpath exports, behind oneSchematicContext, oneSchematicProvider, and one set of hooks — without bloating the bundle for consumers who only need the lightweight surface.@schematichq/schematic-react) — flags / entitlements / events / plan info. ~6 KB ESM. Pulls in nothing beyondreactand@schematichq/schematic-js.@schematichq/schematic-react/components) — same provider plus the REST-backed UI surface (PricingTable,Embed,PaymentMethod, etc.) and embed-side hooks. ~890 KB ESM.The standalone
components/package continues to ship from this monorepo for existing consumers; new code should prefer the/componentssubpath.Architecture
src/context.ts— singleSchematicContextwith shape{ client, embed }.src/provider.tsx— bare plugin host. Composes optionalws/embedadapter components aroundchildren, filters props per-adapter, holds no state itself.src/core/WsAdapter.tsx— WS client adapter. Auto-bound by both entries; passws={null}to opt out.src/components/embed/EmbedAdapter.tsx— heavy REST / reducer / theme / i18n adapter. Only reachable from/components, and even then loaded lazily on firstuseEmbed(or first lazy UI-component mount) via auseSyncExternalStore-backed loader (src/embed-loader.ts).embed={undefined}(lazy, default),embed={EmbedAdapter}(eager mount),embed={null}(explicit opt-out —useEmbedthrows a clear error).scripts/check-tree-shake.mjsruns post-build and fails if@stripe/*,styled-components,i18next,react-i18next, or@schematichq/schematic-iconsleak into the root bundle.Migration
@schematichq/schematic-react(WS-only) users: import surface is unchanged — bump the version.@schematichq/schematic-componentsusers: swap the package name and append/componentsto imports.EmbedProvideris gone — useSchematicProviderfrom/components. TheapiKeyprop is gone;publishableKeynow authenticates both the WS client and the public REST surface.Test plan
yarn buildproduces the expecteddist/shape (root ~6 KB ESM, components ~890 KB ESM) andcheck:tree-shakepassesyarn testis green (vitest + MSW under jsdom)useSchematicFlag/useSchematicEntitlement/useSchematicEventswork against a live WS connection/componentsentry, default (lazy): provider mounts;useEmbed-using subtree showsfallbackuntil the embed chunk loads, then renders the populated UI/componentsentry, eager:embed={EmbedAdapter}starts the chunk loading at provider mount (no fallback flash)/componentsentry, opt-out:embed={null}causesuseEmbedcallers to throw the explicit disabled errorws={null}on/componentsrenders the UI surface without opening a WebSocketfallbackon the server and hydrate on the clientcomponents/package still builds and ships from the monorepo