Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1612b29
Add failing test for non-changing props
luisherranz Oct 15, 2025
6fef0ed
Add failing test for props that only exist in some pages
luisherranz Oct 15, 2025
d6b3298
Add failing test for non-changing props (context)
luisherranz Oct 15, 2025
6ea374c
Add failing test for props that only exist in some pages (context)
luisherranz Oct 15, 2025
fce2ff8
Fix existing tests (state)
luisherranz Oct 15, 2025
605869a
Fix getServerState tests
luisherranz Oct 15, 2025
68589e5
Remove deepImmutable in favor of deepReadOnly
luisherranz Oct 15, 2025
099b8f2
Export deepReadOnly in the private APIs
luisherranz Oct 15, 2025
d77cec5
Simplify signal logic
luisherranz Oct 15, 2025
e5e7b1c
Add failing test for resetting state on pages without state
luisherranz Oct 15, 2025
bcfee9c
Fix reset state test
luisherranz Oct 15, 2025
a7d014a
Add proper types for getServerState
luisherranz Oct 16, 2025
5d0a4ca
Trigger invalidations in the router
luisherranz Oct 16, 2025
7ac95cc
Add additional context test for resetting context
luisherranz Oct 16, 2025
07e4ca3
Add tests for getServerContext types
luisherranz Oct 16, 2025
4f8cb3f
Fix the context tests
luisherranz Oct 16, 2025
f6030ce
Add changelog
luisherranz Oct 16, 2025
2e98558
Don't execute type tests
luisherranz Oct 16, 2025
2835b49
Remove `readOnly` option from proxifyState
luisherranz Oct 16, 2025
4eda5eb
Fix PHP lint
luisherranz Oct 16, 2025
34d4af4
Rename types tests to types
luisherranz Oct 16, 2025
12ad535
Use `Record<string, unknown>` type for non-generic in getServerState
luisherranz Oct 16, 2025
de67848
Use `Record<string, unknown>` type for non-generic in getServerContext
luisherranz Oct 16, 2025
d894949
Update changelog
luisherranz Oct 16, 2025
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
Next Next commit
Add failing test for non-changing props
  • Loading branch information
luisherranz committed Oct 15, 2025
commit 1612b29f21a72ccc73a38d54417ccd79ba03e0bc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

<div
data-wp-interactive="test/get-server-state"
data-wp-watch="callbacks.updateState"
data-wp-watch---update-state="callbacks.updateState"
data-wp-watch---non-changing="callbacks.updateNonChanging"
>
<div data-testid="prop" data-wp-text="state.prop"></div>
<div data-testid="nested.prop" data-wp-text="state.nested.prop"></div>
<div data-testid="newProp" data-wp-text="state.newProp"></div>
<div data-testid="nested.newProp" data-wp-text="state.nested.newProp"></div>
<div data-testid="nonChanging" data-wp-text="state.nonChanging"></div>

<button
data-testid="tryToModifyServerState"
Expand All @@ -30,6 +32,12 @@
modify
</button>

<button
data-testid="updateNonChanging"
data-wp-on--click="actions.updateNonChanging"
>
update non-changing prop
</button>

<nav>
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const { state } = store( 'test/get-server-state', {
getContext().result = 'not modified ✅';
}
},
updateNonChanging() {
state.nonChanging = 'modified from client';
},
},
callbacks: {
updateState() {
Expand All @@ -34,5 +37,12 @@ const { state } = store( 'test/get-server-state', {
state.nested.prop = nested.prop;
state.nested.newProp = nested.newProp;
},
updateNonChanging() {
// This property never changes in the server, but it changes in the
// client so every time there's a navigation, we need to overwrite
// it.
const { nonChanging } = getServerState();
state.nonChanging = nonChanging;
},
},
} );
33 changes: 33 additions & 0 deletions test/e2e/specs/interactivity/get-sever-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test.describe( 'getServerState()', () => {
prop: 'link 1',
newProp: 'link 1',
},
nonChanging: 'modified from server',
},
},
} );
Expand All @@ -29,6 +30,7 @@ test.describe( 'getServerState()', () => {
prop: 'link 2',
newProp: 'link 2',
},
nonChanging: 'modified from server',
},
},
} );
Expand All @@ -42,6 +44,7 @@ test.describe( 'getServerState()', () => {
nested: {
prop: 'main',
},
nonChanging: 'modified from server',
},
},
} );
Expand Down Expand Up @@ -116,4 +119,34 @@ test.describe( 'getServerState()', () => {
await expect( prop ).toHaveText( 'main' );
await expect( button ).toHaveText( 'not modified ✅' );
} );

test( 'should overwrite non-changing props on navigation', async ( {
page,
} ) => {
const nonChanging = page.getByTestId( 'nonChanging' );
const button = page.getByTestId( 'updateNonChanging' );

await expect( page ).toHaveTitle( /main/ );
await expect( nonChanging ).toHaveText( 'modified from server' );

await button.click();

await expect( nonChanging ).toHaveText( 'modified from client' );

await page.getByTestId( 'link 1' ).click();
await expect( page ).toHaveTitle( /link 1/ );

// The prop is overwritten on navigation.
await expect( nonChanging ).toHaveText( 'modified from server' );

await button.click();

await expect( nonChanging ).toHaveText( 'modified from client' );

await page.goBack();
await expect( page ).toHaveTitle( /main/ );

// The prop is overwritten on navigation.
await expect( nonChanging ).toHaveText( 'modified from server' );
} );
} );