From 57e0b99a0dc8fbca08e1983a31f55334a6aa4655 Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Sun, 29 Dec 2024 15:15:44 +0000 Subject: [PATCH] internal: Remove ssr package --- jest.config.js | 9 +- packages/ssr/.gitignore | 3 - packages/ssr/CHANGELOG.md | 212 ------- packages/ssr/LICENSE | 201 ------- packages/ssr/README.md | 273 --------- packages/ssr/data_client_logo_and_text.svg | 63 --- packages/ssr/node.mjs | 1 - packages/ssr/package.json | 147 ----- packages/ssr/rollup.config.mjs | 73 --- packages/ssr/src/ServerData.tsx | 31 - packages/ssr/src/createPersistedStore.tsx | 65 --- .../ssr/src/createServerDataComponent.tsx | 20 - packages/ssr/src/getInitialData.ts | 53 -- packages/ssr/src/index.ts | 9 - packages/ssr/src/nextjs/AppDataProvider.tsx | 28 - .../ssr/src/nextjs/DataClientDocument.tsx | 52 -- .../src/nextjs/DataProvider/DataProvider.tsx | 29 - .../DataProvider/ServerDataComponent.tsx | 17 - .../DataProvider/createPersistedStore.ts | 8 - .../createPersistedStoreClient.tsx | 31 - .../createPersistedStoreServer.tsx | 82 --- packages/ssr/src/nextjs/docType.d.cts | 3 - packages/ssr/src/nextjs/index.ts | 9 - packages/ssr/tsconfig.compile.json | 4 - packages/ssr/tsconfig.json | 12 - tsconfig.json | 1 - yarn.lock | 529 +----------------- 27 files changed, 9 insertions(+), 1956 deletions(-) delete mode 100644 packages/ssr/.gitignore delete mode 100644 packages/ssr/CHANGELOG.md delete mode 100644 packages/ssr/LICENSE delete mode 100644 packages/ssr/README.md delete mode 100644 packages/ssr/data_client_logo_and_text.svg delete mode 100644 packages/ssr/node.mjs delete mode 100644 packages/ssr/package.json delete mode 100644 packages/ssr/rollup.config.mjs delete mode 100644 packages/ssr/src/ServerData.tsx delete mode 100644 packages/ssr/src/createPersistedStore.tsx delete mode 100644 packages/ssr/src/createServerDataComponent.tsx delete mode 100644 packages/ssr/src/getInitialData.ts delete mode 100644 packages/ssr/src/index.ts delete mode 100644 packages/ssr/src/nextjs/AppDataProvider.tsx delete mode 100644 packages/ssr/src/nextjs/DataClientDocument.tsx delete mode 100644 packages/ssr/src/nextjs/DataProvider/DataProvider.tsx delete mode 100644 packages/ssr/src/nextjs/DataProvider/ServerDataComponent.tsx delete mode 100644 packages/ssr/src/nextjs/DataProvider/createPersistedStore.ts delete mode 100644 packages/ssr/src/nextjs/DataProvider/createPersistedStoreClient.tsx delete mode 100644 packages/ssr/src/nextjs/DataProvider/createPersistedStoreServer.tsx delete mode 100644 packages/ssr/src/nextjs/docType.d.cts delete mode 100644 packages/ssr/src/nextjs/index.ts delete mode 100644 packages/ssr/tsconfig.compile.json delete mode 100644 packages/ssr/tsconfig.json diff --git a/jest.config.js b/jest.config.js index adede9fb661d..76987b5db20e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -21,7 +21,6 @@ const baseConfig = { 'DevtoolsManager', 'packages/test', 'packages/graphql', - 'packages/ssr', 'packages/rest/src/next', 'packages/core/src/next', 'packages/react/src/next', @@ -90,8 +89,7 @@ const projects = [ roots: packages.map(pkgName => `/packages/${pkgName}/src`), displayName: 'ReactNative', testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.native\\.(j|t)sx?$', - testEnvironment: - require.resolve('react-native/jest/react-native-env.js'), + testEnvironment: require.resolve('react-native/jest/react-native-env.js'), transformIgnorePatterns: [ 'node_modules\\/(?!(((jest-)?react-native)|@react-native(-community)?|react-navigation))', //from RN preset '/.*__tests__/[^/]+\\.(web|node)\\.(j|t)sx?$', @@ -104,8 +102,9 @@ const projects = [ transform: { //'^.+\\.js$': '/node_modules/react-native/jest/preprocessor.js', //setup.js needs to be transformed, but preprocessor screws everything else up ...baseConfig.transform, - '^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': - require.resolve('react-native/jest/assetFileTransformer.js'), //from RN preset + '^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve( + 'react-native/jest/assetFileTransformer.js', + ), //from RN preset }, haste: { //from RN preset diff --git a/packages/ssr/.gitignore b/packages/ssr/.gitignore deleted file mode 100644 index c8c1925e3bb1..000000000000 --- a/packages/ssr/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/lib -/dist -/legacy diff --git a/packages/ssr/CHANGELOG.md b/packages/ssr/CHANGELOG.md deleted file mode 100644 index c0783ad3d49f..000000000000 --- a/packages/ssr/CHANGELOG.md +++ /dev/null @@ -1,212 +0,0 @@ -# @data-client/ssr - -## 0.12.15 - -### Patch Changes - -- [`4095003`](https://github.com/reactive/data-client/commit/4095003f40f4f6436a790d108ee13bcae1a2cdfa) Thanks [@ntucker](https://github.com/ntucker)! - Improve compatibility with React 19 - -## 0.12.14 - -### Patch Changes - -- [#3134](https://github.com/reactive/data-client/pull/3134) [`2ad1811`](https://github.com/reactive/data-client/commit/2ad1811149cdc419f6462ace08efdb7766195b36) Thanks [@ntucker](https://github.com/ntucker)! - Expand peerdep support range to include ^0.14.0 - -## 0.12.13 - -### Patch Changes - -- [#3105](https://github.com/reactive/data-client/pull/3105) [`cf770de`](https://github.com/reactive/data-client/commit/cf770de244ad890b286c59ac305ceb6c3b1288ea) Thanks [@ntucker](https://github.com/ntucker)! - Support 0.13 of @data-client/react - -## 0.12.12 - -### Patch Changes - -- [#3095](https://github.com/reactive/data-client/pull/3095) [`aab27d9`](https://github.com/reactive/data-client/commit/aab27d956a9b47c2fd5f79869c1e68373c3e5745) Thanks [@ntucker](https://github.com/ntucker)! - CacheProvider -> DataProvider - - CacheProvider name is still usable - -## 0.12.11 - -### Patch Changes - -- [#3080](https://github.com/reactive/data-client/pull/3080) [`559cd8a`](https://github.com/reactive/data-client/commit/559cd8a1bf3d0952eefb37c3e61c01af788a8486) Thanks [@ntucker](https://github.com/ntucker)! - NextJS App Router: Prevent serialization race conditions by stalling client hydration until serialization is complete - -## 0.12.10 - -### Patch Changes - -- [`8493e50`](https://github.com/reactive/data-client/commit/8493e509ec737557d7367cd864b6f72a7d3caa27) Thanks [@ntucker](https://github.com/ntucker)! - Update README to include DataProvider (app routes) docs - -## 0.12.9 - -### Patch Changes - -- [#3074](https://github.com/reactive/data-client/pull/3074) [`1f1f66a`](https://github.com/reactive/data-client/commit/1f1f66a54219d65019f8c3cea380e627b317bbef) Thanks [@ntucker](https://github.com/ntucker)! - Add DataProvider export to /nextjs namespace. - - This provides 'App Router' compatibility. Simply add it to the root layout, ensuring - `children` is rendered as a descendent. - -
- app/layout.tsx - - ```tsx - import { DataProvider } from '@data-client/react/nextjs'; - import { AsyncBoundary } from '@data-client/react'; - - export default function RootLayout({ children }) { - return ( - - - -
Title
- {children} -
-
- - - ); - } - ``` - -
- -- [#3074](https://github.com/reactive/data-client/pull/3074) [`1f1f66a`](https://github.com/reactive/data-client/commit/1f1f66a54219d65019f8c3cea380e627b317bbef) Thanks [@ntucker](https://github.com/ntucker)! - Compatibility with server/client component build rules - -## 0.12.8 - -### Patch Changes - -- [#3071](https://github.com/reactive/data-client/pull/3071) [`7fba440`](https://github.com/reactive/data-client/commit/7fba44050a4e3fdcc37ab8405730b35366c293e1) Thanks [@ntucker](https://github.com/ntucker)! - React 19 JSX runtime compatibility. - - BREAKING CHANGE: Min React version 16.8.4 -> 16.14 - - 16.14 is the first version of React to include JSX runtime. - -## 0.12.3 - -### Patch Changes - -- [`00d4205`](https://github.com/reactive/data-client/commit/00d4205f03562cfe4acd18215718e23ae5466b8d) Thanks [@ntucker](https://github.com/ntucker)! - Add funding package.json field - -## 0.12.2 - -### Patch Changes - -- [`1dcc39b`](https://github.com/reactive/data-client/commit/1dcc39b0ee08bbe5d7aed3bec17050bcad58d406) Thanks [@ntucker](https://github.com/ntucker)! - Relax peerDeps to allow older versions - -## 0.12.1 - -### Patch Changes - -- Updated dependencies [[`5b64cbf`](https://github.com/reactive/data-client/commit/5b64cbf3126c404b70853960a4bdedc268e3328c), [`5b64cbf`](https://github.com/reactive/data-client/commit/5b64cbf3126c404b70853960a4bdedc268e3328c), [`6e9d36b`](https://github.com/reactive/data-client/commit/6e9d36b6cb287763c0fcc3f07d9f2ef0df619d12)]: - - @data-client/react@0.12.1 - - @data-client/redux@0.12.1 - -## 0.11.4 - -### Patch Changes - -- [#3023](https://github.com/reactive/data-client/pull/3023) [`9dea825`](https://github.com/reactive/data-client/commit/9dea825cc979eeb1558f1e686cbbaacee6d137c5) Thanks [@renovate](https://github.com/apps/renovate)! - Compatibility with React 19 by removing defaultProps - -## 0.11.0 - -### Patch Changes - -- [`ba636a7`](https://github.com/reactive/data-client/commit/ba636a74e77bf5cb8c2b327e161db09f4c4a7192) Thanks [@ntucker](https://github.com/ntucker)! - Support 0.11.0 of @data-client pkgs - -## 0.10.0 - -### Patch Changes - -- [#2912](https://github.com/reactive/data-client/pull/2912) [`922be79`](https://github.com/reactive/data-client/commit/922be79169a3eeea8e336eee519c165431ead474) Thanks [@ntucker](https://github.com/ntucker)! - Expand compatibility - -- [`053e823`](https://github.com/reactive/data-client/commit/053e82377bd29f200cd7dfbc700da7a3ad7fa8d7) Thanks [@ntucker](https://github.com/ntucker)! - Update NextJS Demo link - -## 0.9.9 - -### Patch Changes - -- [`e3314a7`](https://github.com/reactive/data-client/commit/e3314a7ca64919c093b838048caaa8b7530fa7c8) Thanks [@ntucker](https://github.com/ntucker)! - docs: Add keywords to package - -- [#2895](https://github.com/reactive/data-client/pull/2895) [`2f3667b`](https://github.com/reactive/data-client/commit/2f3667b90f6b73cb6e856970446d891b1a89f733) Thanks [@renovate](https://github.com/apps/renovate)! - Support redux 5 - -## 0.9.7 - -### Patch Changes - -- [`6c6678bd9d`](https://github.com/reactive/data-client/commit/6c6678bd9d0051c3bf1996c064457ca6f2389c62) Thanks [@ntucker](https://github.com/ntucker)! - docs: README uses svg version of logo - -## 0.9.5 - -### Patch Changes - -- [`bb4b9583c5`](https://github.com/reactive/data-client/commit/bb4b9583c52e2b2fe45765af10b385b571901ee7) Thanks [@ntucker](https://github.com/ntucker)! - docs: Update readme - -## 0.9.4 - -### Patch Changes - -- [`d1b51af7ac`](https://github.com/reactive/data-client/commit/d1b51af7ac4a8a7c0559f478cc9503be8e61514c) Thanks [@ntucker](https://github.com/ntucker)! - Fix unpkg bundles by ensuring dependencies are built in order - -## 0.9.3 - -### Patch Changes - -- [#2818](https://github.com/reactive/data-client/pull/2818) [`fc0092883f`](https://github.com/reactive/data-client/commit/fc0092883f5af42a5d270250482b7f0ba9845e95) Thanks [@ntucker](https://github.com/ntucker)! - Fix unpkg bundles and update names - - - Client packages namespace into RDC - - @data-client/react - RDC - - @data-client/core - RDC.Core - - @data-client/redux - RDC.Redux - - Definition packages namespace top level - - @data-client/rest - Rest - - @data-client/graphql - GraphQL - - @data-client/img - Img - - @data-client/endpoint - Endpoint - - Utility - - @data-client/normalizr - normalizr - - @data-client/use-enhanced-reducer - EnhancedReducer - -## 0.9.2 - -### Patch Changes - -- [`4ea0bc83f6`](https://github.com/reactive/data-client/commit/4ea0bc83f65f49cb2155f6aecdc5f8d1b168fd5e) Thanks [@ntucker](https://github.com/ntucker)! - Docs: Update repo links to reactive organization - -## 0.9.1 - -### Patch Changes - -- [`0cf8f584cc`](https://github.com/reactive/data-client/commit/0cf8f584cc6d6a4635eec4d185063a7eedabebf4) Thanks [@ntucker](https://github.com/ntucker)! - Support 0.9 - -## 0.8.0 - -### Patch Changes - -- [#2779](https://github.com/reactive/data-client/pull/2779) [`ff51e71f45`](https://github.com/reactive/data-client/commit/ff51e71f45857eb172f3fe05829e34c9abb68252) Thanks [@ntucker](https://github.com/ntucker)! - Update jsdocs references to dataclient.io - -## 0.2.1 - -### Patch Changes - -- 15d5cc02ec: Support @data-client/react@0.4.0 - -## 0.2.0 - -### Minor Changes - -- a78831dc61: Support latest version in peerDeps - -## 0.1.2 - -### Patch Changes - -- 7b835f113a: Improve package tags -- 6f3b39b585: Only warn about name mangling when using SSR and only once per type - -## 0.1.1 - -### Patch Changes - -- 5cacc5d0cd: peerDeps compatibility with next versions diff --git a/packages/ssr/LICENSE b/packages/ssr/LICENSE deleted file mode 100644 index ee5e0561fd6c..000000000000 --- a/packages/ssr/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2019 Nathaniel Tucker. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/packages/ssr/README.md b/packages/ssr/README.md deleted file mode 100644 index d971cbf757a9..000000000000 --- a/packages/ssr/README.md +++ /dev/null @@ -1,273 +0,0 @@ -# [![Reactive Data Client](./data_client_logo_and_text.svg?sanitize=true)](https://dataclient.io) - -[![CircleCI](https://circleci.com/gh/reactive/data-client/tree/master.svg?style=shield)](https://circleci.com/gh/reactive/data-client) -[![Coverage Status](https://img.shields.io/codecov/c/gh/reactive/data-client/master.svg?style=flat-square)](https://app.codecov.io/gh/reactive/data-client?branch=master) -[![npm downloads](https://img.shields.io/npm/dm/@data-client/ssr.svg?style=flat-square)](https://www.npmjs.com/package/@data-client/ssr) -[![npm version](https://img.shields.io/npm/v/@data-client/ssr.svg?style=flat-square)](https://www.npmjs.com/package/@data-client/ssr) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) -[![Chat](https://img.shields.io/discord/768254430381735967.svg?style=flat-square&colorB=758ED3)](https://discord.gg/35nb8Mz) - -
- -**[📖Read The Docs](https://dataclient.io/docs/guides/ssr)**  |  -[🎮NextJS Demo](https://stackblitz.com/github/reactive/data-client/tree/master/examples/nextjs?file=components%2Ftodo%2FTodoList.tsx) - -
- -Hydrate/dehydration utilities for Server Side Rendering with the [Reactive Data Client](https://dataclient.io) - -## Usage - -Integration with - -- [NextJS](https://dataclient.io/docs/guides/ssr#nextjs) -- Anansi - ```bash - npx @anansi/cli hatch my-project - ``` -- [ExpressJS](https://dataclient.io/docs/guides/ssr#express-js) - -For more details, see the [Server Side Rendering docs page](https://dataclient.io/docs/guides/ssr). - -## NextJS - -### App Router - -Place [DataProvider](https://dataclient.io/docs/api/DataProvider) in your [root layout](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required) - -
-app/layout.tsx - -```tsx -import { DataProvider } from '@data-client/ssr/nextjs'; -import { AsyncBoundary } from '@data-client/react'; - -export default function RootLayout({ children }) { - return ( - - - -
Title
- {children} -
-
- - - ); -} -``` - -
- -Any endpoints can be used in server components by simply awaiting them - -```tsx -export default async function StaticPage() { - const todos = await TodoResource.getList(); - return ; -} -``` - -Or used in client components - meaning their state can be mutated client-side with `useSuspense()` - - -```tsx -'use client'; -import { useSuspense } from '@data-client/react'; - -export default function InteractivePage() { - const todos = useSuspense(TodoResource.getList); - return ; -} -``` - -### Pages Router - -We've optimized integration into NextJS with a custom [Document](https://nextjs.org/docs/advanced-features/custom-document) -and NextJS specific wrapper for [App](https://nextjs.org/docs/advanced-features/custom-app) - -
pages/_document.tsx - -```tsx -import { DataClientDocument } from '@data-client/ssr/nextjs'; - -export default DataClientDocument; -``` - -
- -
pages/_app.tsx - -```tsx -import { AppDataProvider } from '@data-client/ssr/nextjs'; - -export default function App({ Component, pageProps }: AppProps) { - return ( - - - - ); -} -``` - -
- -### Further customizing Document - -To further customize Document, simply extend from the provided document. - -Make sure you use `super.getInitialProps()` instead of `Document.getInitialProps()` -or the Data Client code won't run! - -
pages/_document.tsx - -```tsx -import { Html, Head, Main, NextScript } from 'next/document' -import { DataClientDocument } from '@data-client/ssr/nextjs'; - -export default class MyDocument extends DataClientDocument { - static async getInitialProps(ctx) { - const originalRenderPage = ctx.renderPage - - // Run the React rendering logic synchronously - ctx.renderPage = () => - originalRenderPage({ - // Useful for wrapping the whole react tree - enhanceApp: (App) => App, - // Useful for wrapping in a per-page basis - enhanceComponent: (Component) => Component, - }) - - // Run the parent `getInitialProps`, it now includes the custom `renderPage` - const initialProps = await super.getInitialProps(ctx) - - return initialProps - } - - render() { - return ( - - - -
- - - - ) - } -} -``` - -
- -### CSP Nonce - -Data Client Document serializes the store state in a script tag. In case you have -Content Security Policy restrictions that require use of a nonce, you can override -`DataClientDocument.getNonce`. - -Since there is no standard way of handling [nonce](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) -in NextJS, this allows you -to retrieve any nonce you created in the DocumentContext to use with Data Client. - -
pages/_document.tsx - -```tsx -import { DataClientDocument } from '@data-client/ssr/nextjs'; - -export default class MyDocument extends DataClientDocument { - static getNonce(ctx: DocumentContext) { - // this assumes nonce has been added here - customize as you need - return ctx.res.nonce; - } -} -``` - -
- -## Express JS - -### Server side - -```tsx -import express from 'express'; -import { renderToPipeableStream } from 'react-dom/server'; -import { - createPersistedStore, - createServerDataComponent, -} from '@data-client/ssr'; - -const rootId = 'react-root'; - -const app = express(); -app.get('/*', (req: any, res: any) => { - const [ServerDataProvider, useReadyCacheState, controller] = - createPersistedStore(); - const ServerDataComponent = createServerDataComponent(useReadyCacheState); - - controller.fetch(NeededForPage, { id: 5 }); - - const { pipe, abort } = renderToPipeableStream( - ]} - rootId={rootId} - > - {children} - , - - { - onCompleteShell() { - // If something errored before we started streaming, we set the error code appropriately. - res.statusCode = didError ? 500 : 200; - res.setHeader('Content-type', 'text/html'); - pipe(res); - }, - onError(x: any) { - didError = true; - console.error(x); - res.statusCode = 500; - pipe(res); - }, - }, - ); - // Abandon and switch to client rendering if enough time passes. - // Try lowering this to see the client recover. - setTimeout(abort, 1000); -}); - -app.listen(3000, () => { - console.log(`Listening at ${PORT}...`); -}); -``` - -### Client - -```tsx -import { hydrateRoot } from 'react-dom'; -import { awaitInitialData } from '@data-client/ssr'; - -const rootId = 'react-root'; - -awaitInitialData().then(initialState => { - hydrateRoot( - document.getElementById(rootId), - {children}, - ); -}); -``` - -## API - -### createPersistedStore(managers) => [ServerDataProvider, useReadyCacheState, controller, store] - -Used to server side render cache. Renders <ServerDataComponent/> inside to serialize cache so client can hydrate. - -### createServerDataComponent(useReadyCacheState, id = 'data-client-data') - -Contents are a script with JSON encoding of cache state sent from server. Be sure to place outside hydration -element so React will not need to hydrate it. - -### getInitialData(id = 'data-client-data') => Promise(State) - -Resolves promise with serialized initialState to pass to <DataProvider /> diff --git a/packages/ssr/data_client_logo_and_text.svg b/packages/ssr/data_client_logo_and_text.svg deleted file mode 100644 index 61d76e32b674..000000000000 --- a/packages/ssr/data_client_logo_and_text.svg +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/ssr/node.mjs b/packages/ssr/node.mjs deleted file mode 100644 index 2b8395cdb631..000000000000 --- a/packages/ssr/node.mjs +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/index.js'; diff --git a/packages/ssr/package.json b/packages/ssr/package.json deleted file mode 100644 index 4ea8fd754632..000000000000 --- a/packages/ssr/package.json +++ /dev/null @@ -1,147 +0,0 @@ -{ - "name": "@data-client/ssr", - "version": "0.12.15", - "description": "Server Side Rendering helpers for Data Client", - "homepage": "https://dataclient.io/docs/guides/ssr", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com:reactive/data-client.git", - "directory": "packages/ssr" - }, - "bugs": { - "url": "https://github.com/reactive/data-client/issues" - }, - "keywords": [ - "front-end", - "web", - "ssr", - "server side rendering", - "incremental hydration", - "react", - "universal", - "suspense", - "nextjs", - "query", - "mutation", - "fetch", - "data", - "cache", - "subscription", - "model", - "typescript", - "data fetching", - "data cache", - "api", - "normalized cache", - "graph", - "swr", - "endpoint", - "networking" - ], - "sideEffects": false, - "main": "dist/index.js", - "react-native": "legacy/index.js", - "module": "legacy/index.js", - "unpkg": "dist/index.umd.min.js", - "types": "lib/index.d.ts", - "typesVersions": { - ">=4.0": { - "": [ - "lib/index.d.ts" - ], - "nextjs": [ - "lib/nextjs/index.d.ts" - ], - "*": [ - "lib/index.d.ts" - ] - }, - ">=3.4": { - "": [ - "ts3.4/index.d.ts" - ], - "nextjs": [ - "ts3.4/nextjs/index.d.ts" - ], - "*": [ - "ts3.4/index.d.ts" - ] - } - }, - "exports": { - ".": { - "module": "./lib/index.js", - "import": "./node.mjs", - "require": "./dist/index.js", - "default": "./lib/index.js" - }, - "./nextjs": { - "types": "./lib/nextjs/index.d.ts", - "default": "./lib/nextjs/index.js" - }, - "./package.json": "./package.json" - }, - "type": "module", - "engines": { - "node": "^12.17 || ^13.7 || >=14" - }, - "files": [ - "src", - "dist", - "lib", - "node.mjs", - "legacy", - "ts3.4", - "LICENSE", - "README.md", - "./data_client_logo_and_text.svg" - ], - "scripts": { - "build:lib": "NODE_ENV=production BROWSERSLIST_ENV='2020' yarn g:babel --out-dir lib", - "build:legacy:lib": "NODE_ENV=production BROWSERSLIST_ENV='2018' yarn g:babel --out-dir legacy", - "build:js:node": "BROWSERSLIST_ENV=node12 yarn g:rollup", - "build:js:browser": "BROWSERSLIST_ENV=legacy yarn g:rollup", - "build:bundle": "yarn g:runs build:js:\\* && echo '{\"type\":\"commonjs\"}' > dist/package.json", - "build:clean": "yarn g:clean", - "build:legacy-types": "yarn g:downtypes lib ts3.4", - "build": "run build:lib && run build:legacy:lib && run build:bundle", - "dev": "run build:lib -w", - "prepare": "run build:lib", - "prepack": "run prepare && run build:bundle && run build:legacy:lib" - }, - "author": "Nathaniel Tucker (https://github.com/ntucker)", - "funding": "https://github.com/sponsors/ntucker", - "license": "Apache-2.0", - "dependencies": { - "@babel/runtime": "^7.17.0" - }, - "peerDependencies": { - "@data-client/react": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0", - "@data-client/redux": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0", - "@types/react": "^16.14.0 || ^17.0.0 || ^18.0.0-0 || ^19.0.0", - "next": ">=12.0.0", - "react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", - "redux": "^4.0.0 || ^5.0.0" - }, - "peerDependenciesMeta": { - "@types/react": { - "optional": true - }, - "next": { - "optional": true - } - }, - "devDependencies": { - "@anansi/browserslist-config": "^1.4.2", - "@data-client/react": "workspace:*", - "@data-client/redux": "^0.13.0", - "@types/node": "^22.0.0", - "@types/react": "19.0.2", - "@types/react-dom": "19.0.2", - "next": "^15.0.0", - "react": "19.0.0", - "react-dom": "19.0.0", - "redux": "^5.0.0", - "rollup-plugins": "workspace:*" - } -} diff --git a/packages/ssr/rollup.config.mjs b/packages/ssr/rollup.config.mjs deleted file mode 100644 index 92719b449848..000000000000 --- a/packages/ssr/rollup.config.mjs +++ /dev/null @@ -1,73 +0,0 @@ -import { babel, banner, commonjs, filesize, json, resolve, replace, terser } from 'rollup-plugins'; - -import pkg from './package.json' with { type: 'json' }; - -const dependencies = Object.keys(pkg.dependencies) - .concat(Object.keys(pkg.peerDependencies)) - .concat(['@data-client/core', 'data-client']) - .filter(dep => !['@babel/runtime'].includes(dep)); -const peers = Object.keys(pkg.peerDependencies); - -const extensions = ['.js', '.ts', '.tsx', '.mjs', '.json', '.node']; -const nativeExtensions = ['.native.ts', ...extensions]; -process.env.NODE_ENV = 'production'; - -function isExternal(id) { - return dependencies.some(dep => dep === id || id.startsWith(dep)); -} -const configs = []; -if (process.env.BROWSERSLIST_ENV !== 'node12') { - // browser-friendly UMD build - configs.push({ - input: 'lib/index.js', - external: id => peers.some(dep => dep === id || id.startsWith(dep)), - output: [ - { - file: pkg.unpkg, - format: 'umd', - name: 'RDC.SSR', - globals: { - '@data-client/react': 'RDC', - '@data-client/redux': 'RDC.Redux', - redux: 'Redux', - react: 'React', - }, - }, - ], - plugins: [ - babel({ - exclude: ['node_modules/**', '/**__tests__/**'], - extensions, - rootMode: 'upward', - runtimeHelpers: true, - }), - replace({ 'process.env.NODE_ENV': JSON.stringify('production') }), - resolve({ extensions }), - commonjs({ extensions }), - json(), - terser({}), - filesize({ showBrotliSize: true }), - ], - }); -} else { - // node-friendly commonjs build - configs.push({ - input: 'lib/index.js', - external: isExternal, - output: [{ file: pkg.main, format: 'cjs' }], - plugins: [ - babel({ - exclude: ['node_modules/**', '**/__tests__/**', '**/*.d.ts'], - extensions: nativeExtensions, - rootMode: 'upward', - runtimeHelpers: true, - }), - replace({ 'process.env.CJS': 'true' }), - resolve({ extensions: nativeExtensions }), - commonjs({ extensions: nativeExtensions }), - // for nextjs 13 compatibility in node https://nextjs.org/docs/app/building-your-application/rendering - banner(() => "'use client';\n"), - ], - }); -} -export default configs; diff --git a/packages/ssr/src/ServerData.tsx b/packages/ssr/src/ServerData.tsx deleted file mode 100644 index 8479d4d73caa..000000000000 --- a/packages/ssr/src/ServerData.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import type { State } from '@data-client/redux'; - -export const ServerData = ({ - data, - nonce, - id = 'data-client-data', -}: { - data: State; - id?: string; - nonce?: string | undefined; -}) => { - try { - const encoded = JSON.stringify(data); - return ( -