Skip to content

Commit 9c11273

Browse files
fix(runtime): guard page bootstrap contract
Agent-Logs-Url: https://github.com/Starisian-Technologies/sparxstar-starmus-audio/sessions/8a8980e0-073d-4308-b02a-fe8fde421acc Co-authored-by: MaximillianGroup <34328348+MaximillianGroup@users.noreply.github.com>
1 parent fd3b137 commit 9c11273

6 files changed

Lines changed: 27 additions & 18 deletions

src/core/StarmusAssetLoader.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,18 @@ private function build_bootstrap_merge_script(): string
425425
return <<<'JS'
426426
// The asset loader composes the final runtime bootstrap immediately before this
427427
// bundle executes. Only page-surface fields may override the base bootstrap.
428-
window.STARMUS_BOOTSTRAP = Object.assign(
429-
{},
430-
window.STARMUS_BOOTSTRAP_BASE || {},
431-
((page) => ({
432-
pageType: page.pageType,
433-
mode: page.mode,
434-
postId: page.postId,
435-
canCommit: page.canCommit,
436-
artifact: page.artifact,
437-
hosts: page.hosts,
438-
}))(window.STARMUS_BOOTSTRAP_PAGE || {})
439-
);
428+
window.STARMUS_BOOTSTRAP = Object.assign({}, window.STARMUS_BOOTSTRAP_BASE || {});
429+
430+
if (window.STARMUS_BOOTSTRAP_PAGE && typeof window.STARMUS_BOOTSTRAP_PAGE === "object") {
431+
window.STARMUS_BOOTSTRAP = Object.assign(window.STARMUS_BOOTSTRAP, {
432+
pageType: window.STARMUS_BOOTSTRAP_PAGE.pageType || "unknown",
433+
mode: window.STARMUS_BOOTSTRAP_PAGE.mode || "unknown",
434+
postId: window.STARMUS_BOOTSTRAP_PAGE.postId || 0,
435+
canCommit: Boolean(window.STARMUS_BOOTSTRAP_PAGE.canCommit),
436+
artifact: window.STARMUS_BOOTSTRAP_PAGE.artifact || window.STARMUS_BOOTSTRAP.artifact,
437+
hosts: window.STARMUS_BOOTSTRAP_PAGE.hosts || null,
438+
});
439+
}
440440
JS;
441441
}
442442

src/core/StarmusUiPackageResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
private readonly string $base_path = ''
2828
) {
2929
if ($this->base_url === '' || $this->base_path === '') {
30-
throw new InvalidArgumentException('StarmusUiPackageResolver requires non-empty base URL and base path.');
30+
throw new InvalidArgumentException('StarmusUiPackageResolver requires both base_url and base_path to be non-empty strings.');
3131
}
3232
}
3333

src/js/starmus-main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,21 @@ function getRuntimeBootstrap() {
137137
// STARMUS_BOOTSTRAP is composed by PHP via wp_add_inline_script(..., 'before')
138138
// immediately before this bundle executes, so the merged object is the
139139
// authoritative runtime contract for initialization.
140+
if (!window.STARMUS_BOOTSTRAP_PAGE || typeof window.STARMUS_BOOTSTRAP_PAGE !== "object") {
141+
console.warn("[StarmusMain] Missing STARMUS_BOOTSTRAP_PAGE.");
142+
return null;
143+
}
144+
140145
if (!window.STARMUS_BOOTSTRAP || typeof window.STARMUS_BOOTSTRAP !== "object") {
141146
console.warn("[StarmusMain] Missing STARMUS_BOOTSTRAP.");
142147
return null;
143148
}
144149

145-
if (!window.STARMUS_BOOTSTRAP.pageType || !window.STARMUS_BOOTSTRAP.hosts) {
150+
if (
151+
!window.STARMUS_BOOTSTRAP.pageType ||
152+
window.STARMUS_BOOTSTRAP.pageType === "unknown" ||
153+
!window.STARMUS_BOOTSTRAP.hosts
154+
) {
146155
console.warn("[StarmusMain] Incomplete STARMUS_BOOTSTRAP.");
147156
return null;
148157
}

src/templates/starmus-audio-editor-ui.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
<!-- JS Bootstrap Data -->
4444
<script>
45-
window.STARMUS_BOOTSTRAP_PAGE = JSON.parse('<?php echo esc_js((string) wp_json_encode($bootstrap_page, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)); ?>');
46-
window.STARMUS_EDITOR_DATA = JSON.parse('<?php echo esc_js((string) wp_json_encode($editor_data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)); ?>');
45+
window.STARMUS_BOOTSTRAP_PAGE = <?php echo wp_json_encode($bootstrap_page, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>;
46+
window.STARMUS_EDITOR_DATA = <?php echo wp_json_encode($editor_data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>;
4747
</script>
4848

4949

src/templates/starmus-audio-re-recorder-ui.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
];
4242
?>
4343
<script>
44-
window.STARMUS_BOOTSTRAP_PAGE = JSON.parse('<?php echo esc_js((string) wp_json_encode($bootstrap_page, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)); ?>');
44+
window.STARMUS_BOOTSTRAP_PAGE = <?php echo wp_json_encode($bootstrap_page, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>;
4545
</script>
4646
<div class="starmus-audio-re-recorder-wrapper" data-starmus="recorder" data-starmus-mode="update" data-starmus-instance="<?php echo esc_attr($instance_id); ?>">
4747
<div class="starmus-recorder-form sparxstar-glass-card">

src/templates/starmus-audio-recorder-ui.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
?>
5555
<script>
56-
window.STARMUS_BOOTSTRAP_PAGE = JSON.parse('<?php echo esc_js((string) wp_json_encode($bootstrap_page, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)); ?>');
56+
window.STARMUS_BOOTSTRAP_PAGE = <?php echo wp_json_encode($bootstrap_page, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>;
5757
</script>
5858
<div class="starmus-audio-recorder-wrapper" data-starmus="recorder" data-starmus-mode="create" data-starmus-instance="<?php echo esc_attr($instance_id); ?>">
5959
<div id="starmus-app" class="starmus-recorder-form sparxstar-glass-card">

0 commit comments

Comments
 (0)