-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Full Site Editing: Update the Content Slot block #32529
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
Am I missing something from readme steps? Trying to build the plugin I see:
Edit: ah I think an extra |
Looks like a nice improvement @Copons As you noted there's a number of interactions we can tidy. I'm not sure if my local WP environment is a bit messy, so if someone can confirm that this preview block loads after a publish/refresh and edit again without block invalidation I think this is good to 🚢 |
per_page: 20, | ||
search, | ||
} ), | ||
} ); |
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.
we probably want to make sure this throttle( apiFetch )
combination works the way we expect it to
the fetchAllMiddleware()
might do some funky business here and we could potentially end up loading all the posts on the first few letters of autocomplete then proceed to reload a subset of those on and on until the end
we also probably want a debounce()
instead of a throttle
because we want the last-typed letters to trigger the last autocomplete search and throttle()
might drop them if they were typed quickly after the previous query
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.
You're correct, I've meant to use debounce
and I've also forgot to add the wait time.
It looks to me it's working correctly, I can't find a case in which this would end up in an infinite loop of some sort. 🤔
(Also, the search is only triggered when the query is 2 or more characters long, and returns 20 results top)
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.
returns 20 results top
this is strange to me. I can't figure out why it's the case but I can't get my search results to fetch all of the result pages. I see a proper Link
header when not making calls to dotcom sites and the botched link header on dotcom sites. I thought that the way we mangle this header in our custom middleware replacements could be behind the behavior but I had trouble getting the auto-paging to work in a core-only test.
here's what I'm worried about: I think that it's a bug somewhere preventing the fetchAllMiddleware
from continuing to pull in all successive search results, so even with per_page=20
it should fetch all the results automatically. That's my understanding, at least. I am not seeing the middleware do that but I'm at a loss for an explanation of why.
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'm not familiar with api-fetch
, but I gave a look at fetchAllMiddleware
and as it turns out it's only applied when the request explicitly asks for all results by "unbounding" the limit with per_page=-1
:
const requestContainsUnboundedQuery = ( options ) => {
const pathIsUnbounded = options.path && options.path.indexOf( 'per_page=-1' ) !== -1;
const urlIsUnbounded = options.url && options.url.indexOf( 'per_page=-1' ) !== -1;
return pathIsUnbounded || urlIsUnbounded;
};
// ...
if ( ! requestContainsUnboundedQuery( options ) ) {
// If neither url nor path is requesting all items, do not apply middleware.
return next( options );
}
} ); | ||
return; | ||
} | ||
await updateSuggestions( inputValue, setState ); |
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.
what's the purpose of the await
here?
updateSuggestions()
will return a Promise under the hood but we're neither waiting on the resolution of that promise nor using its returned value, so I think we can disregard the await
and the async
in the function signature
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.
Good catch.
It was a leftover from a temporary fix long gone. 🙂
d49424d
to
f6bab9d
Compare
I've rebased to the most recent master, which might fix @gwwar installation issue. The new build system introduced in #32431 creates a new |
Working on the Content Renderer block I've realized that storing the entire post object in the block attributes means that:
In other words, if we select a post to preview, and then we edit that post, the preview would not be updated accordingly. In f6d8ab7 I've slightly changed the selected post loading:
Practically speaking, nothing visible changes. |
f6d8ab7
to
0c206af
Compare
0c206af
to
965fdb4
Compare
I may be misreading the code, but we'd probably want a dynamic block (have a To recap we
|
@gwwar this block is supposed to be used in a template to mark where to render a post content. We don't really need to store the preview post ID and type (actually, thinking about it, it probably makes things more confusing), but my tests felt smoother if the preview post persisted across reloads. This is as opposed to the Content Renderer block (names could use some improvements 😄), introduced in #32581 (branched out from this PR). Content Renderer would be used to add layout elements (or anything really: why stop at header and footer when we might want to "embed" an entire post, say, in the sidebar?) to a template. |
I agree with @gwwar regarding the dynamic block point, but if you'd prefer to do so, I think it's fine to handle that in a follow-up (we just need to make sure to write out the follow-up task for it). Regarding the "how" part, I think this was already handled in the early prototype here: https://github.com/dmsnell/stupid-code-do-not-use/blob/a8910a9720bb506841410c85b83429a1e932d5b2/fse/fse.php#L33.
I think it makes things more confusing too - every template is supposed to be referenced by multiple posts down the road. Assigning a particular
Which makes me wonder whether we really need two separate block types for this? 😄They are confusing me now and I guess the difference won't be clear to users either. In light of my comments here #32581 (comment), we could consider merging this functionality into one block, that will behave differently depending on the context:
Having just one block might make things easier to grok conceptually (cc @dmsnell for thoughts). We could call it something like [Layout|Template] [part|component|element]. |
Ok, let's take a step back here. 🙂 I'm opposed to have 1 block for both functionalities. So: I 100% agree that the current naming is totally messed up (tbh I wasn't really paying attention to it for now).
Am I missing anything? |
Sorry, I now see that I grabbed a link to a wrong render callback. (got confused by those names once again! 😄) |
@Copons do you mind adding a readme file that states what this block is intended to be used for, why, and maybe add a quick example of serialized post_content. |
reusable: false, | ||
}, | ||
edit, | ||
save: () => null, |
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.
at a later point in time or even now I think it's worth spitting some output here.
this is somewhat high-level and not a priority at this point, but one of our guiding principles is being part of the open web. I would love to see some fallback message here for the case where a post is viewed purely as HTML without WordPress the PHP engine rendering it.
could we think of a simple message to report that would convey "this is the spot where a post would normally show, but this page is being viewed without the necessary software so you get this instead 😄 "
$align = isset( $attributes['align'] ) ? ' align' . $attributes['align'] : ''; | ||
|
||
$content = '<div class="a8c-content'. $align . '">' | ||
. __( '[Renders some content]' ) |
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. ha. see my above comment in the static render fallback. note that while we are free to render this here, we can also send that into the editor, and even have both. but if we have the static fallback render this isn't entirely necessary.
return await apiFetch( { | ||
path: `/wp/v2/${ postTypeObject.rest_base }/${ postId }`, | ||
} ); | ||
}; |
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.
can we explain why this exists and why we aren't using getEntityRecord()
to fetch the post?
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 under the impression that getEntityRecord
was a simple selector, but in fact it has a resolver that apiFetch
es on its own.
I'll see to update this behaviour ASAP.
Changes proposed in this Pull Request
select
with the latest 10 posts) with an autosuggestion field roughly inspired byURLInput
.Note: the accessibility interactions between the input field and the popover should be improved.
Core handles keyboard events to move the cursor from one side to the other.
I have omitted it because it's a pretty good chunk of code, but we should take care of it in a follow up.
Note: the render callback for this block depends on the theme, and will be tackled in a follow-up.
Testing instructions
npm distclean
andnpm ci
first (required because of a recentcalypso-build
change).public
CPTs), and make sure the results are as expected.Fixes #32492