-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Send post_id to the REST API in the ServerSideRender component within the Editor #9323
Merged
jorgefilipecosta
merged 8 commits into
WordPress:master
from
alexsanford:fix/post-id-wrapper-for-ssr
Sep 12, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dda93e9
Add custom URL query arguments to ServerSideRender
alexsanford 954dcf7
Add wrapper to editor package for ServerSideRender
alexsanford 996fa1f
Add README
alexsanford 5ac43df
Update block library components to use ServerSideRender wrapper
alexsanford 495b788
Simplify addition of urlQueryArgs
alexsanford 7c8408f
Add more explanation to README
alexsanford 2cd708c
Ensure we accept incoming urlQueryArgs rather than blindly overriding…
alexsanford 0c8481c
Move editor ServerSideRender into components subdirectory
alexsanford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ServerSideRender | ||
|
||
This utility component is a wrapper for the generic ServerSideRender in `@wordpress/components`. It adds the `post_id` parameter to the `urlQueryArgs` prop of the wrapped component. Use this component to ensure that the global `$post` object is set up properly in the server-side `render_callback` when rendering within the editor. |
18 changes: 18 additions & 0 deletions
18
packages/editor/src/components/server-side-render/index.js
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,18 @@ | ||
/** | ||
* WordPress dependencies. | ||
*/ | ||
import { ServerSideRender } from '@wordpress/components'; | ||
import { select } from '@wordpress/data'; | ||
|
||
export default function( { urlQueryArgs = {}, ...props } ) { | ||
const { getCurrentPostId } = select( 'core/editor' ); | ||
|
||
urlQueryArgs = { | ||
post_id: getCurrentPostId(), | ||
...urlQueryArgs, | ||
}; | ||
|
||
return ( | ||
<ServerSideRender urlQueryArgs={ urlQueryArgs } { ...props } /> | ||
); | ||
} |
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.
Given this is an exported function, do we need to keep (or deprecate) the original
rendererPathWithAttributes()
?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.
Phrased another way: maybe we should keep the name as
rendererPathWithAttributes()
, and it simply supports a thirdurlQueryArgs
argument.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.
Hi @danielbachhuber, the function rendererPathWithAttributes is exported just for testing but is not exported outside of @wordpress/components as we only export the default export outside of the module (the component)
gutenberg/packages/components/src/index.js
Line 51 in 0c8481c
No plugin could have used this function so even if we change the name I don't think deprecations are necessary.
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.
Ah, makes sense. Thanks for clarifying @jorgefilipecosta