Skip to content

Commit

Permalink
Don’t echo fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Oct 15, 2024
1 parent 6f5660d commit 986d994
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
16 changes: 0 additions & 16 deletions src/services/ResponseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ public function init(): void
$this->response = new DatastarResponse();
}

/**
* Returns whether the request is a Spark request.
*/
public function getIsRequest(): bool
{
return Craft::$app->getRequest()->getHeaders()->get('datastar-request') === 'true';
}

/**
* Processes the response.
*/
Expand All @@ -62,10 +54,6 @@ public function process(string $config, array $params): void
*/
public function runAction(string $route, array $params): ?array
{
if (!$this->getIsRequest()) {
return null;
}

Craft::$app->getRequest()->getHeaders()->set('Accept', 'application/json');
$response = Craft::$app->runAction($route, $params);

Expand All @@ -90,10 +78,6 @@ public function setStore(array $values): void

private function sendEvent(string $type, string $content, array $options = []): void
{
if (!$this->getIsRequest()) {
return;
}

$this->id++;

$event = new DatastarEvent([
Expand Down
3 changes: 1 addition & 2 deletions src/twigextensions/nodes/FragmentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function compile(Compiler $compiler): void

$compiler
->raw(";\n")
->write(Spark::class . "::\$plugin->response->sendFragment(\$content, \$options);\n")
->write("echo \$content;\n");
->write(Spark::class . "::\$plugin->response->sendFragment(\$content, \$options);\n");
}
}
2 changes: 1 addition & 1 deletion src/variables/SparkVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function delete(string $template, array $variables = []): string
*/
public function getIsRequest(): bool
{
return Spark::$plugin->response->getIsRequest();
return Craft::$app->getRequest()->getHeaders()->get('datastar-request') === 'true';
}

/**
Expand Down

0 comments on commit 986d994

Please sign in to comment.