@@ -130,8 +130,6 @@ function enqueue_assets( $directory, $opts = [] ) {
130
130
$ defaults = [
131
131
'base_url ' => '' ,
132
132
'handle ' => basename ( $ directory ),
133
- 'scripts ' => [],
134
- 'styles ' => [],
135
133
];
136
134
137
135
$ opts = wp_parse_args ( $ opts , $ defaults );
@@ -144,7 +142,11 @@ function enqueue_assets( $directory, $opts = [] ) {
144
142
}
145
143
146
144
if ( empty ( $ assets ) ) {
147
- // TODO: This should be an error condition.
145
+ if ( WP_DEBUG ) {
146
+ handle_assets_error ();
147
+ }
148
+
149
+ trigger_error ( 'React WP Scripts Error: Unable to find React asset manifest ' , E_USER_WARNING );
148
150
return ;
149
151
}
150
152
@@ -189,3 +191,110 @@ function enqueue_assets( $directory, $opts = [] ) {
189
191
wp_enqueue_style ( $ opts ['handle ' ] );
190
192
}
191
193
}
194
+
195
+ /**
196
+ * Display an overlay error when the React bundle cannot be loaded. It also stops the execution.
197
+ *
198
+ * @param array $details
199
+ */
200
+ function handle_assets_error ( $ details = [] ) {
201
+ ?>
202
+ <style>
203
+ /**
204
+ * Copyright (c) 2015-present, Facebook, Inc.
205
+ *
206
+ * This source code is licensed under the MIT license found in the
207
+ * LICENSE file in the root directory of this source tree.
208
+ */
209
+
210
+ /* @flow */
211
+
212
+ html, body {
213
+ overflow: hidden;
214
+ }
215
+
216
+ .error-overlay {
217
+ position: fixed;
218
+ top: 0;
219
+ left: 0;
220
+ width: 100%;
221
+ height: 100%;
222
+ border: none;
223
+ z-index: 1000;
224
+
225
+ --black: #293238;
226
+ --dark-gray: #878e91;
227
+ --red: #ce1126;
228
+ --red-transparent: rgba(206, 17, 38, 0.05);
229
+ --light-red: #fccfcf;
230
+ --yellow: #fbf5b4;
231
+ --yellow-transparent: rgba(251, 245, 180, 0.3);
232
+ --white: #ffffff;
233
+ }
234
+
235
+ .error-overlay .wrapper {
236
+ width: 100%;
237
+ height: 100%;
238
+ box-sizing: border-box;
239
+ text-align: center;
240
+ background-color: var( --white );
241
+ }
242
+
243
+ .primaryErrorStyle {
244
+ background-color: var( --red-transparent );
245
+ }
246
+
247
+ .error-overlay .overlay {
248
+ position: relative;
249
+ display: inline-flex;
250
+ flex-direction: column;
251
+ height: 100%;
252
+ width: 1024px;
253
+ max-width: 100%;
254
+ overflow-x: hidden;
255
+ overflow-y: auto;
256
+ padding: 0.5rem;
257
+ box-sizing: border-box;
258
+ text-align: left;
259
+ font-family: Consolas, Menlo, monospace;
260
+ font-size: 13px;
261
+ line-height: 2;
262
+ color: var( --black );
263
+ }
264
+
265
+ .header {
266
+ font-size: 2em;
267
+ font-family: sans-serif;
268
+ color: var( --red );
269
+ white-space: pre-wrap;
270
+ margin: 0 2rem 0.75rem 0;
271
+ flex: 0 0 auto;
272
+ max-height: 50%;
273
+ overflow: auto;
274
+ }
275
+
276
+ .error-content {
277
+ padding:1rem;
278
+ }
279
+
280
+ code {
281
+ background-color: rgba(27,31,35,.05);
282
+ margin: 0;
283
+ padding: .2em .4em;
284
+ }
285
+ </style>
286
+ <div class="error-overlay">
287
+ <div class="wrapper primaryErrorStyle">
288
+ <div class="overlay">
289
+ <div class="header">Failed to render</div>
290
+ <div class="error-content primaryErrorStyle">
291
+ Unable to find React asset manifest.
292
+ <code>react-wp-scripts</code> was unable to find either a development or production asset manifest.
293
+ Run <code>npm start</code> to start the development server or <code>npm run build</code> to build a production bundle.
294
+ </div>
295
+ </div>
296
+ </div>
297
+ </div>
298
+ <?php
299
+ die ();
300
+ }
0 commit comments