Skip to content
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

WIP: update core and next packages to next15 and react19. #873

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,493 changes: 967 additions & 526 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"wp/*"
],
"devDependencies": {
"@10up/eslint-config": "^4.0.0",
"@10up/eslint-config": "^4.1.0",
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
Expand Down
185 changes: 95 additions & 90 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,97 @@
{
"name": "@headstartwp/core",
"version": "1.5.0-next.7",
"description": "`@headstartwp/core` is the core package that houses framework-agnostic components and utilities for building headless sites with WordPress.",
"homepage": "https://github.com/10up/headstartwp/blob/develop/packages/core/README.md",
"license": "MIT",
"author": "10up <[email protected]> (https://10up.com/)",
"main": "dist/cjs/index.js",
"source": "src/index.ts",
"types": "dist/mjs/index.d.ts",
"typedocMain": "src/docs-entry-point.ts",
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/mjs/index.js",
"types": "./dist/mjs/index.d.ts"
},
"./utils": {
"require": "./dist/cjs/utils/index.js",
"import": "./dist/mjs/utils/index.js",
"types": "./dist/mjs/utils/index.d.ts"
},
"./react": {
"react-server": {
"import": "./dist/mjs/rsc/index.js",
"require": "./dist/cjs/rsc/index.js",
"types": "./dist/mjs/rsc/index.d.ts"
},
"require": "./dist/cjs/react/index.js",
"import": "./dist/mjs/react/index.js",
"types": "./dist/mjs/react/index.d.ts"
},
"./rsc": {
"import": "./dist/mjs/rsc/index.js",
"require": "./dist/cjs/rsc/index.js",
"types": "./dist/mjs/rsc/index.d.ts"
},
"./test": "./test/server.ts"
},
"files": [
"dist",
"react.d.ts",
"react.js",
"test.d.ts",
"utils.d.ts",
"utils.js"
],
"sideEffects": false,
"scripts": {
"postbuild": "tsc-esm-fix --target dist/mjs && node ../../scripts/package.js",
"build": "npm run ts && npm run ts:cjs",
"ts:cjs": "tsc -b tsconfig-cjs.json",
"ts": "tsc -b",
"dev": "concurrently \"npm run watch:ts:cjs\" \"npm run watch:ts\"",
"watch:ts:cjs": "npm run ts:cjs -- --watch",
"watch:ts": "npm run ts -- --watch",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint src/"
},
"devDependencies": {
"@testing-library/dom": "^10.3.1",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.0.3",
"@types/node-fetch": "^2.5.3",
"expect-type": "^0.15.0",
"jest": "^29.3.1",
"msw": "^0.35.0",
"ts-jest": "^29.0.3",
"typescript": "^5.5.3",
"isomorphic-fetch": "^3.0.0",
"tsc-esm-fix": "^2.20.27",
"@types/react": "^18",
"@types/react-dom": "^18"
},
"dependencies": {
"@justinribeiro/lite-youtube": "^1.3.1",
"html-react-parser": "^3.0.4",
"path-to-regexp": "^6.2.0",
"react-inspector": "^6.0.1",
"swr": "^2.2.5",
"xss": "^1.0.15",
"deepmerge": "^4.3.1",
"schema-dts": "^1.1.2"
},
"peerDependencies": {
"react": ">= 17.0.2"
}
"name": "@headstartwp/core",
"version": "1.5.0-next.7",
"description": "`@headstartwp/core` is the core package that houses framework-agnostic components and utilities for building headless sites with WordPress.",
"homepage": "https://github.com/10up/headstartwp/blob/develop/packages/core/README.md",
"license": "MIT",
"author": "10up <[email protected]> (https://10up.com/)",
"main": "dist/cjs/index.js",
"source": "src/index.ts",
"types": "dist/mjs/index.d.ts",
"typedocMain": "src/docs-entry-point.ts",
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/mjs/index.js",
"types": "./dist/mjs/index.d.ts"
},
"./utils": {
"require": "./dist/cjs/utils/index.js",
"import": "./dist/mjs/utils/index.js",
"types": "./dist/mjs/utils/index.d.ts"
},
"./react": {
"react-server": {
"import": "./dist/mjs/rsc/index.js",
"require": "./dist/cjs/rsc/index.js",
"types": "./dist/mjs/rsc/index.d.ts"
},
"require": "./dist/cjs/react/index.js",
"import": "./dist/mjs/react/index.js",
"types": "./dist/mjs/react/index.d.ts"
},
"./rsc": {
"import": "./dist/mjs/rsc/index.js",
"require": "./dist/cjs/rsc/index.js",
"types": "./dist/mjs/rsc/index.d.ts"
},
"./test": "./test/server.ts"
},
"files": [
"dist",
"react.d.ts",
"react.js",
"test.d.ts",
"utils.d.ts",
"utils.js"
],
"sideEffects": false,
"scripts": {
"postbuild": "tsc-esm-fix --target dist/mjs && node ../../scripts/package.js",
"build": "npm run ts && npm run ts:cjs",
"ts:cjs": "tsc -b tsconfig-cjs.json",
"ts": "tsc -b",
"dev": "concurrently \"npm run watch:ts:cjs\" \"npm run watch:ts\"",
"watch:ts:cjs": "npm run ts:cjs -- --watch",
"watch:ts": "npm run ts -- --watch",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint src/"
},
"devDependencies": {
"@testing-library/dom": "^10.3.1",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.0.3",
"@types/node-fetch": "^2.5.3",
"expect-type": "^0.15.0",
"jest": "^29.3.1",
"msw": "^0.35.0",
"ts-jest": "^29.0.3",
"typescript": "^5.5.3",
"isomorphic-fetch": "^3.0.0",
"tsc-esm-fix": "^2.20.27",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]"
},
"dependencies": {
"@justinribeiro/lite-youtube": "^1.3.1",
"html-react-parser": "^3.0.4",
"path-to-regexp": "^6.2.0",
"react-inspector": "^6.0.1",
"swr": "^2.2.5",
"xss": "^1.0.15",
"deepmerge": "^4.3.1",
"schema-dts": "^1.1.2"
},
"peerDependencies": {
"react": ">= 19.0.0"
},
"overrides": {
"swr": {
"react": "19.0.0-rc-66855b96-20241106"
}
}
}
17 changes: 12 additions & 5 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
"@headstartwp/core": "^1.5.0-next.6",
"loader-utils": "^3.2.0",
"schema-utils": "^4.0.0",
"@isaacs/ttlcache": "^1.4.1"
"@isaacs/ttlcache": "^1.4.1",
"next": "15.0.3",
"react": "19.0.0-rc-66855b96-20241106",
"react-dom": "19.0.0-rc-66855b96-20241106"
},
"devDependencies": {
"@testing-library/dom": "^10.3.1",
Expand All @@ -77,11 +80,15 @@
"isomorphic-fetch": "^3.0.0",
"jest-fetch-mock": "^3.0.3",
"tsc-esm-fix": "^2.20.27",
"@types/react": "^18",
"@types/react-dom": "^18"
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]"
},
"peerDependencies": {
"next": ">= 12.0.0",
"react": ">= 17.0.2"
"next": "15.0.3",
"react": "19.0.0-rc-66855b96-20241106"
},
"overrides": {
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]"
}
}
9 changes: 6 additions & 3 deletions packages/next/src/rsc/actions/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { redirect } from 'next/navigation';
import { COOKIE_NAME } from '../handlers/previewRouteHandler';

export async function disableDraftMode() {
const currentUrl = headers().get('x-headstartwp-current-url') ?? '/';
draftMode().disable();
cookies().delete(COOKIE_NAME);
const cookieStore = await cookies();
const headerStore = await headers();
const draftmode = await draftMode();
const currentUrl = headerStore.get('x-headstartwp-current-url') ?? '/';
draftmode.disable();
cookieStore.delete(COOKIE_NAME);
redirect(currentUrl);
}
4 changes: 2 additions & 2 deletions packages/next/src/rsc/components/PreviewIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export type PreviewIndicatorProps = {
className?: string;
};

export const PreviewIndicator: React.FC<PreviewIndicatorProps> = ({ className }) => {
const { isEnabled } = draftMode();
export const PreviewIndicator: React.FC<PreviewIndicatorProps> = async ({ className }) => {
const { isEnabled } = await draftMode();

if (!isEnabled) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/rsc/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { prepareQuery } from './data/queries/prepareQuery';
*
* @returns
*/
export function loadHeadstartWPConfig(routeParams: HeadstartWPRoute['params']) {
export function loadHeadstartWPConfig(routeParams: Awaited<HeadstartWPRoute['params']>) {
const { config } = prepareQuery({ routeParams });

return config;
Expand Down
9 changes: 5 additions & 4 deletions packages/next/src/rsc/data/queries/queryPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export async function queryPost<
const { config, handleError, ...query } = prepareQuery<P>(nextQuery, _config);

try {
const { isEnabled } = draftMode();
const { isEnabled, disable } = await draftMode();
const cookieStore = await cookies();

if (isEnabled) {
// the cookie will only exist for the previewed path
if (cookies().has(COOKIE_NAME)) {
if (cookieStore.has(COOKIE_NAME)) {
const previewData: PreviewData = JSON.parse(
cookies().get(COOKIE_NAME)?.value ?? '{}',
cookieStore.get(COOKIE_NAME)?.value ?? '{}',
);

if (!query.params) {
Expand All @@ -49,7 +50,7 @@ export async function queryPost<
}
} else {
// if draft mode was enabled but no preview cookie was found, disable draft mode
draftMode().disable();
disable();
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/next/src/rsc/handlers/previewRouteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export async function previewRouteHandler(
const is_revision = searchParams.get('is_revision');
const token = searchParams.get('token');
const locale = searchParams.get('locale');
const cookieStore = await cookies();
const draftmode = await draftMode();

// check if post_id, post_type and token is set
if (!post_id || !token || !post_type) {
Expand Down Expand Up @@ -214,14 +216,14 @@ export async function previewRouteHandler(
})
: defaultRedirectPath;

cookies().set(COOKIE_NAME, JSON.stringify(previewData), {
cookieStore.set(COOKIE_NAME, JSON.stringify(previewData), {
maxAge: 5 * 60,
// remove trailing slash
path: redirectPath.replace(/\/$/, ''),
httpOnly: true,
});

draftMode().enable();
draftmode.enable();

if (typeof options.onRedirect === 'function') {
options.onRedirect({
Expand Down
5 changes: 3 additions & 2 deletions packages/next/src/rsc/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export type HeadstartWPRoute<Params extends { [k: string]: unknown } = {}> = {
params: { path: string[]; site?: string; lang?: string };
params: Promise<{ path: string[]; site?: string; lang?: string }>;
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
} & Params;

export type HeadstartWPLayout<Params extends { [k: string]: unknown } = {}> = {
params: { site?: string; lang?: string };
params: Promise<{ site?: string; lang?: string }>;
children: React.ReactNode;
} & Params;
Loading
Loading