Skip to content

Commit

Permalink
Do not render state when data is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Feb 22, 2024
1 parent 1172bb0 commit ece2467
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
array( 'clientNavigationDisabled' => true )
);
}

if ( isset( $attributes['data'] ) ) {
$initial_state = array( 'router' => array( 'data' => $attributes['data'] ) );
}
?>

<div
Expand Down Expand Up @@ -65,5 +69,5 @@
</div>

<script type="application/json" id="wp-interactivity-initial-state">
{ "router": { "data": <?php echo json_encode( $attributes['state'] ); ?> } }
<?php echo isset( $initial_state ) ? json_encode( $initial_state ) : '{}'; ?>
</script>
4 changes: 2 additions & 2 deletions test/e2e/specs/interactivity/router-navigate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ test.describe( 'Router navigate', () => {
alias: 'router navigate - link 1',
attributes: {
title: 'Link 1',
state: { prop1: 'link 1', prop3: 'link 1' },
data: { prop1: 'link 1', prop3: 'link 1' },
},
} );
await utils.addPostWithBlock( 'test/router-navigate', {
alias: 'router navigate - main',
attributes: {
title: 'Main',
links: [ link1, link2 ],
state: { prop1: 'main', prop2: 'main' },
data: { prop1: 'main', prop2: 'main' },
},
} );
await utils.addPostWithBlock( 'test/router-navigate', {
Expand Down

0 comments on commit ece2467

Please sign in to comment.