Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ describe('core-data-shim fetch → cache', () => {
// wiped but `hasFinishedResolution` stayed true, so the next
// read returned the empty wiped cache forever — until the user
// refreshed the page.
const listFetcher = vi.fn(async (url: string) => {
const listFetcher = vi.fn(async (input: RequestInfo | URL, _init?: RequestInit) => {
const url = String(input);
if (url.includes('per_page=-1')) {
return jsonResponse({
data: [
Expand Down Expand Up @@ -569,7 +570,8 @@ describe('core-data-shim fetch → cache', () => {

configureCoreDataShim({
apiBase: '/api',
fetcher: vi.fn(async (url: string) => {
fetcher: vi.fn(async (input: RequestInfo | URL, _init?: RequestInit) => {
const url = String(input);
if (url.includes('per_page=-1')) {
listFetchCount += 1;

Expand Down Expand Up @@ -1725,9 +1727,10 @@ describe('core-data-shim hooks', () => {
},
]);

const [blocks] = renderHook(() =>
const [rawBlocks] = renderHook(() =>
useEntityBlockEditor('postType', 'wp_template_part', { id: 1 }),
) as readonly Array<{
);
const blocks = rawBlocks as ReadonlyArray<{
name: string;
clientId: string;
isValid: true;
Expand Down Expand Up @@ -1774,9 +1777,10 @@ describe('core-data-shim hooks', () => {
},
]);

const [blocks] = renderHook(() =>
const [rawBlocks] = renderHook(() =>
useEntityBlockEditor('postType', 'wp_navigation', { id: 42 }),
) as readonly Array<{
);
const blocks = rawBlocks as ReadonlyArray<{
name: string;
clientId: string;
attributes: Record<string, unknown>;
Expand Down
11 changes: 6 additions & 5 deletions resources/js/visual-editor/vendor/core-data-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,10 @@ const actions = {

const edited = select.getEditedEntityRecord(kind, name, id);

if (edited === null) {
return null;
}

const config = select.getEntityConfig(kind, name);
const payload: EntityRecord = config
? { ...edited, [config.key]: id }
Expand Down Expand Up @@ -1986,11 +1990,8 @@ export function useEntityProp<T = unknown>(
const ambientId = useEntityId();
const resolvedId = id !== undefined && id !== null ? id : ambientId;

const { editedValue, fullValue } = useSelect<{
editedValue: T | undefined;
fullValue: T | undefined;
}>(
(select) => {
const { editedValue, fullValue } = useSelect(
(select: <S>(store: S) => unknown) => {
if (
kind === undefined ||
name === undefined ||
Expand Down
Loading