Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is which hook fits better here as there are two possibilities in contrast to the front end:
admin_footer
- Prints scripts or data before the default footer scripts.admin_print_footer_scripts
- Prints any scripts and data queued for the footer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the configs and initial state for stores so it probably needs to be printer earlier 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good question! I think I'd print this as late as possible.
@wordpress/interactivity
is what will use this when it initializes, and because that's a module the DOM should have finished parsing before it runs.I think we can switch this to
admin_print_footer_scripts
to print it as late as possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was exploring that part of the codebase for the first time today. I still don't know what should be the order of printing when taking into account also 3rd party plugins that depend on Interactivity API. My initial thinking was that 3rd party plugins would use
admin_enqueue_scripts
to register/enqueue their scripts. I'm not sure how folks would usewp_interactivity_store
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed that change, I can see the script moved after the footer scripts and it continues to work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's
@wordpress/interactivity
itself that reads data from the printed store data. And because these are modules (which implies defer) there shouldn't be any problem pushing the printed script tag to be later. The module that depends on it will not execute until the DOM has been parsed completely, so the script tag it looks for will be there.