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
4 changes: 4 additions & 0 deletions packages/global-styles-engine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- `getResolvedValue`: Return a copy when resolving a theme-relative (`file:./…`) URL instead of writing the resolved URL onto the given object, which could be the caller's own value or, via a `ref`, an object aliased by the user or theme config ([#82278](https://github.com/WordPress/gutenberg/pull/82278)).

## 1.21.0 (2026-08-26)

### Bug Fixes
Expand Down
23 changes: 23 additions & 0 deletions packages/global-styles-engine/src/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,28 @@ describe( 'editor utils', () => {
).toEqual( returnedValue );
}
);

it( 'returns a copy instead of writing the resolved URL onto the given value', () => {
const ruleValue = { url: 'file:./assets/image.jpg' };
expect( getResolvedValue( ruleValue, themeJson ) ).toEqual( {
url: 'https://wordpress.org/assets/image.jpg',
} );
expect( ruleValue.url ).toBe( 'file:./assets/image.jpg' );
} );

it( 'does not write the resolved URL into the tree when resolving a ref', () => {
const tree = JSON.parse(
JSON.stringify( themeJson )
) as GlobalStylesConfig;
expect(
getResolvedValue(
{ ref: 'styles.background.backgroundImage' },
tree
)
).toEqual( { url: 'https://wordpress.org/assets/image.jpg' } );
expect( tree.styles?.background?.backgroundImage ).toEqual( {
url: 'file:./assets/image.jpg',
} );
} );
} );
} );
16 changes: 12 additions & 4 deletions packages/global-styles-engine/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,18 @@ export function getResolvedValue(
'url' in resolvedValue &&
resolvedValue?.url
) {
resolvedValue.url = getResolvedThemeFilePath(
resolvedValue.url,
tree?._links?.[ 'wp:theme-file' ]
);
/*
* Copy rather than write in place: `resolvedValue` is the caller's
* own object or, when a `ref` was just resolved, the tree's — which
* aliases the user or theme config.
*/
return {
...resolvedValue,
url: getResolvedThemeFilePath(
resolvedValue.url,
tree?._links?.[ 'wp:theme-file' ]
),
};
}

return resolvedValue;
Expand Down
Loading