Skip to content

Commit

Permalink
DEBUG fix uncollected callbacks by analysing stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Aug 28, 2022
1 parent dae4dc2 commit c592b8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/JsReload.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function dumpRenderTree(View $view, bool $rec = false): void

public function jsRender(): string
{
ini_set('output_buffering', (string) (1024 * 1024));
/*ini_set('output_buffering', (string) (1024 * 1024));
ob_start();
$this->dumpRenderTree($this->view);
// test URL: /demos/interactive/modal.php?__atk_m=atk_layout_maestro_modal_5&__atk_cbtarget=atk_layout_maestro_modal_5_view_callbacklater&__atk_cb_atk_layout_maestro_modal_5_view_callbacklater=ajax&__atk_json=1
Expand All @@ -66,7 +66,7 @@ public function jsRender(): string
echo 'expected: string(166) "modal.php?__atk_m=atk_layout_maestro_modal_5&__atk_cb_atk_layout_maestro_modal_5_view_callbacklater=ajax&__atk_reload=atk_layout_maestro_modal_5_view_demos_viewtester"' . "\n";
ob_end_flush();
exit;
exit;*/

$final = (new Jquery($this->view))
->atkReloadView(
Expand Down
34 changes: 34 additions & 0 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,40 @@ protected function getRunningCallbackArgs(bool $isTerminated, array $page): arra
$parentRenderView = $this->getOwner();
} // else

if (($this instanceof Modal || $this instanceof Panel\Content/* || $this instanceof Panel\Right no direct callback, must use something like mergeStickyArgsFromChildView */) && $this->cb !== null && $this->cb->isTriggered() && $this->cb->canTrigger()) { // hack for modals placed outside the render tree with possible callbacks
$isTerminated = true; // fake terminated detection to support https://github.com/atk4/ui/blob/8014b6c1cb5beb103f337af8ace5ac350f73ce19/src/JsReload.php#L58 URL built not thru callback

$stacktrace = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS);
foreach (array_slice($stacktrace, 1, null, true) as $k => $stackframe) {
if (($stackframe['object'] ?? null) instanceof self && ($stackframe['object'] ?? null) !== $this) {
$parentRenderView = $stackframe['object'];
foreach (array_slice($stacktrace, $k + 1) as $stackframe2) {
if (($stackframe2['object'] ?? null) === $parentRenderView && $stackframe2['function'] === 'getRunningCallbackArgs') {
$parentRenderView = null; // already called
}
}

break;
} elseif (($stackframe['object'] ?? null) instanceof App && ($stackframe['function'] ?? null) === 'run') {
break;
}
}

if ($parentRenderView !== null) {
$a = [
array_map(function ($v) {
$v['class'] = isset($v['object']) ? get_class($v['object']) : 'x';
unset($v['object']);

return $v;
}, $stacktrace),
$parentRenderView !== null ? $parentRenderView->getRunningCallbackArgs($isTerminated, $page) : '-----',
$page,
];
// print_r($a);
}
}

if ($parentRenderView !== null) {
$args = array_merge($parentRenderView->getRunningCallbackArgs($isTerminated, $page), $args);
}
Expand Down

0 comments on commit c592b8f

Please sign in to comment.