Skip to content
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
2 changes: 1 addition & 1 deletion resources/js/components/entries/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export default {
},

showLivePreviewButton() {
return !this.isPreviewing && !this.readOnly && !this.isCreating && this.isBase && this.livePreviewUrl;
return !this.isPreviewing && !this.readOnly && this.isBase && this.livePreviewUrl;
},

showVisitUrlButton() {
Expand Down
9 changes: 7 additions & 2 deletions src/Stache/Repositories/EntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,13 @@ public static function bindings(): array

public function substitute($item)
{
Blink::store('entry-uris')->forget($item->id());
$this->substitutionsById[$item->id()] = $item;
// An entry being previewed before its first save has no id yet,
// so it can only be found by its URI.
if ($id = $item->id()) {
Blink::store('entry-uris')->forget($id);
$this->substitutionsById[$id] = $item;
}

$this->substitutionsByUri[$item->locale().'@'.$item->uri()] = $item;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Feature/Entries/SubstitutesEntryForLivePreviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Facades\Tests\Factories\EntryFactory;
use Illuminate\Support\Facades\Route;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Collection;
use Statamic\Facades\Entry;
use Statamic\Facades\Token;
use Statamic\View\View;
Expand Down Expand Up @@ -70,6 +71,25 @@ public function it_substitutes()
->assertHeader('X-Statamic-Live-Preview', true);
}

#[Test]
public function it_substitutes_an_entry_that_has_not_been_saved_yet()
{
Collection::make('test')->routes('/test/{slug}')->template('entry')->save();
$this->viewShouldReturnRaw('layout', '{{ template_content }}');
$this->viewShouldReturnRaw('entry', '{{ title }} {{ foo }}');

$substitute = EntryFactory::collection('test')->slug('delta')->data(['title' => 'New title', 'foo' => 'New foo'])->make();
LivePreview::tokenize('test-token', $substitute);

$this->assertNull($substitute->id());

$this->get('/test/delta?token=test-token')
->assertOk()
->assertSee('New title')
->assertSee('New foo')
->assertHeader('X-Statamic-Live-Preview', true);
}

#[Test]
public function it_doesnt_substitute()
{
Expand Down
Loading