-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from wp-graphql/fix/issue-124-drawer-delay
fix: Defer script to reduce the initial delay w/ opening of drawer
- Loading branch information
Showing
12 changed files
with
174 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"wpgraphql-ide": patch | ||
--- | ||
|
||
- fix: The IDE no longer waits on `DOMContentLoaded` in order to help client side performance with heavier pages. | ||
- add: New PHP filters for updating the drawer label: | ||
- `wpgraphqlide_drawer_button_label` | ||
- `wpgraphqlide_drawer_button_loading_label` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
// WordPress dependencies for hooks, data handling, and component rendering. | ||
/** | ||
* @file | ||
* Initializes the WPGraphQL IDE by setting up the necessary WordPress hooks, | ||
* registering the global store, and exposing the GraphQL functionality through a global IDE object. | ||
*/ | ||
|
||
// External dependencies | ||
import { createHooks } from '@wordpress/hooks'; | ||
import { register } from '@wordpress/data'; | ||
import { createRoot } from '@wordpress/element'; | ||
import * as GraphQL from "graphql/index.js"; | ||
import * as GraphQL from 'graphql/index.js'; | ||
|
||
// Local imports including the store configuration and the main App component. | ||
// Internal dependencies | ||
import { store } from './store'; | ||
import { App } from './App'; | ||
|
||
// Register the store with wp.data to make it available throughout the plugin. | ||
/** | ||
* Registers the application's data store with WordPress to enable global state management. | ||
*/ | ||
register( store ); | ||
|
||
// Create a central event hook system for the WPGraphQL IDE. | ||
/** | ||
* Initializes a hooks system to extend the functionality of the WPGraphQL IDE through | ||
* external scripts and internal plugin hooks. | ||
*/ | ||
export const hooks = createHooks(); | ||
|
||
// Expose a global variable for the IDE, facilitating extension through external scripts. | ||
/** | ||
* Exposes a global `WPGraphQLIDE` variable that includes hooks, store, and GraphQL references, | ||
* making them accessible for extensions and external scripts. | ||
*/ | ||
window.WPGraphQLIDE = { | ||
hooks, | ||
store, | ||
GraphQL | ||
GraphQL, | ||
}; | ||
|
||
/** | ||
* Initialize and render the application once the DOM is fully loaded. | ||
* This ensures that the application mounts when all page elements are available. | ||
* Attempts to render the React application to a specified mount point in the DOM. | ||
* Logs an error to the console if the mount point is missing. | ||
*/ | ||
document.addEventListener( 'DOMContentLoaded', () => { | ||
const appMountPoint = document.getElementById( 'wpgraphql-ide-root' ); | ||
if ( appMountPoint ) { | ||
createRoot( appMountPoint ).render( <App /> ); | ||
} else { | ||
console.error( | ||
'WPGraphQL IDE mount point not found. Please ensure an element with ID "wpgraphql-ide-root" exists.' | ||
); | ||
} | ||
} ); | ||
const appMountPoint = document.getElementById( 'wpgraphql-ide-root' ); | ||
if ( appMountPoint ) { | ||
createRoot( appMountPoint ).render( <App /> ); | ||
} else { | ||
console.error( | ||
'WPGraphQL IDE mount point not found. Please ensure an element with ID "wpgraphql-ide-root" exists.' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { loginToWordPressAdmin, visitPluginsPage } from '../utils'; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await loginToWordPressAdmin(page); | ||
}); | ||
|
||
test( 'expect the enqueued wpgraphql-ide script to have the defer attribute', async ( { page } ) => { | ||
await visitPluginsPage( page ); | ||
|
||
// Retrieve the script tags and check for the defer attribute | ||
const hasDeferAttribute = await page.evaluate( () => { | ||
const scripts = Array.from( document.querySelectorAll( 'script' ) ); | ||
const targetScript = scripts.find( script => script.src.includes( 'wpgraphql-ide' ) ); | ||
return targetScript?.hasAttribute( 'defer' ); | ||
}); | ||
|
||
// Assert that the defer attribute is present | ||
expect( hasDeferAttribute ).toBe( true ); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters