| @@ -83,11 +83,19 @@ | ||
| 83 | 83 | wp_register_script( |
| 84 | 84 | 'os-starter-widget', // Handle name — passed as 'script' to openstation_register_widget(). |
| 85 | 85 | OPENSTATION_URL . 'assets/js/widget-starter' . $suffix . '.js', |
| 86 | 86 | array( 'wp-api-fetch' ), // List WordPress script handles your widget depends on. |
| 87 | - // 'wp-api-fetch' is available on every admin page and handles | |
| 88 | - // REST nonces automatically. Remove it if your widget does | |
| 89 | - // not make REST API calls. | |
| 87 | + // Declare every WordPress package you use, and do not assume any | |
| 88 | + // of them are already on the page. They used to be: Core's ⌘K | |
| 89 | + // palette pulled the whole Gutenberg runtime onto every admin | |
| 90 | + // screen, so `wp.apiFetch`, `wp.element` and friends happened to | |
| 91 | + // be globals by the time any widget mounted. Deferring that | |
| 92 | + // runtime to the first ⌘K took the accident away — on a fresh | |
| 93 | + // boot they are undefined until the palette is opened, and a | |
| 94 | + // widget that reached for one at mount threw. A declared | |
| 95 | + // dependency is resolved by WordPress when the script is | |
| 96 | + // enqueued, which is why this line is the fix and not a | |
| 97 | + // workaround. See docs/migration-wp-package-globals.md. | |
| 90 | 98 | file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version, |
| 91 | 99 | true // Load in the footer — always true for widget scripts. |
| 92 | 100 | ); |
| 93 | 101 | } |