Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Script Enqueueing #162

Open
jasonbahl opened this issue Jun 3, 2024 · 0 comments
Open

Conditional Script Enqueueing #162

jasonbahl opened this issue Jun 3, 2024 · 0 comments

Comments

@jasonbahl
Copy link
Collaborator

With the WPGraphQL IDE being enqueued by core WPGraphQL, in order to opt-in to "bleeding edge" when the WPGraphQL IDE plugin is active, the plugin should override the enqueueing of scripts to be relative to the plugin and not relative to core.

Initial Proposal (Relative asset path constants)

  • $path is defined as a relative location for where JS/Style/Asset files are enqueued from (i.e. /wp-graphql/build)
  • If plugin is active, the $path is overridden with a directory relative to the plugin (i.e. /wpgraphql-ide/build`)
  • Simply having the WPGraphQL IDE plugin active loads the assets from the plugin instead of from core
  • Plugin could be as simple as (pseudo):
<?php
/**
 * Plugin Name: WPGraphQL IDE
 * ...
 * /

define( 'WPGRAPHQL_IDE_ASSETS_DIR', dirname( __FILE__ ) );
define( 'WPGRAPHQL_IDE_ASSETS_PATH', __FILE__ );
define( 'WPGRAPHQL_IDE_VERSION', '2.0.0-beta.1' );

These constants could be picked up by core and used to enqueue the assets from the plugin instead of core, and could display the version of the IDE being used.

Problems with this approach

In this approach, the assumption is that all assets will be the same, but just their locations will be different. This is flaky.

If we decide to change names of assets (i.e. we recently changed the main index.js to ide.js and render.js) then the new assets would not be enqueued by core because the relative path isn't the only thing that changed, different files altogether would need to be enqueued.


Perhaps the entire "enqueue_react_app_with_styles" function needs to be a pluggable function or something?

i.e.

public function enqueue_react_app_with_styles(): void {

  // if the wpgraphql_ide_enqueue_app function exists, use it to enqueue assets 
  if ( function_exists( 'wpgraphql_ide_enqueue_app' ) {
    wpgraphql_ide_enqueue_app();
    return;
  }

  // else, do default enqueuing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant