🔥 feat(nexts): Introducing bound Optimization components#355
Draft
Charles Hudson (phobetron) wants to merge 1 commit into
Draft
🔥 feat(nexts): Introducing bound Optimization components#355Charles Hudson (phobetron) wants to merge 1 commit into
Charles Hudson (phobetron) wants to merge 1 commit into
Conversation
724deea to
9508d2d
Compare
Introduce createNextjsOptimizationComponents() as the primary Next.js SDK integration surface. The factory binds application config once and returns app-local OptimizationRoot, OptimizationProvider, OptimizedEntry, and route tracker components that resolve to the correct server or client runtime implementation. - Add the root @contentful/optimization-nextjs entrypoint for bound component creation - Add automatic server components that resolve request consent, cookies, headers, server optimization data, entry variants, merge tags, and server-to-browser state handoff - Add the matching client component factory that reuses the same app-local API while removing server-only config - Remove the empty root entrypoint and make the package default runtime point at the client build with a react-server conditional export - Replace page-level NextjsOptimizationState usage with bound root/provider serverOptimizationState handoff - Extend React Web OptimizedEntry render props with getMergeTagValue and export OptimizedEntryRenderContext - Update SSR and hybrid Next.js reference implementations to use app-local bound components for server first paint, browser takeover, tracking, and merge tag rendering - Share entry-card rich text rendering helpers across server and client examples - Update Next.js, React Web, and conceptual docs for the new bound component model, manual escape hatches, consent, locale, profile synchronization, tracking, and merge tag guidance - Add tests for automatic server components and update client and React Web tests for the new render context BREAKING CHANGE: NextjsOptimizationState is removed from the client entrypoint. Pass server optimization data through OptimizationRoot or OptimizationProvider via serverOptimizationState, or use createNextjsOptimizationComponents() to let the bound root/provider handle server-to-browser state handoff. [[NT-3560](https://contentful.atlassian.net/browse/NT-3560)]
9508d2d to
75f0298
Compare
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
This PR introduces
createNextjsOptimizationComponents()as the primary public Next.js SDK integration API. Consumers can now bind Optimization SDK configuration once in an app-local module and use the returnedOptimizationRoot,OptimizationProvider,OptimizedEntry, and route trackers across server and client rendering boundaries.The change also extends the React Web
OptimizedEntryrender-prop contract with a shared render context that includesgetMergeTagValue, updates the Next.js SSR and Hybrid reference implementations to use the new API, and refreshes the docs around consent, locale handling, profile handoff, tracking, and merge tag rendering.Example usage
Architectural and design changes
createNextjsOptimizationComponents().serverOptimizationStatehandoff./server,/client,/esr,/request-handler,/tracking-attributes, and/api-schemasas lower-level escape hatches for custom flows.index.tsentrypoint.NextjsOptimizationStatein favor ofserverOptimizationStatehandoff through root/provider components, or automatic handoff through the bound component factory.OptimizedEntryrender props from(resolvedEntry)to(resolvedEntry, context), wherecontext.getMergeTagValueis available to rich text renderers.Benefits to consumers
cookies(),headers(), server SDK instances, request helpers, page-level state markers, and matching client provider props for the common path.OptimizedEntryshape across SSR and hybrid patterns.Benefits to maintainers
Reference implementation rendering improvements
Beyond adopting bound optimization components, the Next.js SSR and Hybrid examples also improve rendering structure:
EntryCardContentrendering so server and client entry cards use the same rich text, nested-entry, click-target, and test-attribute behavior.getMergeTagValuefromOptimizedEntryrender props into rich text render options, aligning merge-tag rendering with the resolved entry/profile context.SKIP_NO_JSfrom the SSR example env flags.[NT-3560]