-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Link Control UI Opens for Last Inserted Block when returning to the Site Editor Right Sidebar Navigation Inserter #50601
Comments
I remember this. Nice work narrowing down the cause. Can we just have a ref somewhere that tracks whether a block was inserted during whilst the current instance of the List View was mounted. If it wasn't then don't do the link UI thing. |
I think the reducer will set the lastBlockInserted state on
I suspect our code dispatches one of those actions which causes the lastInsertedBlock to be all the blocks in the menu. So we need to distinguish between a user action (i.e. user added this block) and an automattic action. |
I the answer to this relies on distinguishing between "this was the last block added" and "this was the block the user just added". We only want to show Link UI in the later case.
I'm exploring another route now. |
Related #50733 (comment) |
ResearchWhat's the problem we're trying to solve?There are two Issues. The one in this Issue and the one in #50733. These are closely related. Why do we care about the last inserted block?This is required in order to display the Link UI for the block that was most recently inserted into the List View. This is because when you click the appender and then select a block, a new block gets inserted into the list view. We then need to grab the clientId of that freshly inserted block and display the Link UI in order that the user can configure the link for that block. What problems does this cause?In this Issue, the problem is that the selector For example, I click on What solution do we need?We need way to keep track of which was the last block that was inserted by the by the user in this currently rendered list view. That way we can conditionally display the Link UI based on the last block inserted into the current List View rather than the last block inserted anywhere within the editor. The benefit of this approach would be that a block would only be considered "last inserted" for the currently rendered list view. As soon as the list view unmounts the information about "last inserted" would be discarded, meaning that when the list view is opened again, there will be no "last inserted block" and thus the Link UI will not display. How is this related to #50733?This issue in #50733 is also related to reliance on Remember that multiple Navigation blocks can contain the same menu. Changes to one block will therefore trigger updates to the inner blocks in another block if it's using the same menu. THe issue is that when there are x2 Nav block in the same template, the Again, if the implementation relied on local state to determine the "last inserted" this would not be an issue. Files
Potential RoutesPassing Values via List View ContextIdea: Pass context along with the This won't work because the code that controls displaying the Link UI (both for appender and submenu-based) insertion resides in the Nav block code and not within the List View so it doesn't have the necessary Update: actually it might work if we can pass the appropriate context value through to both Passing "Insertion Context" in the State ActionIdea: Make the last inserted block information local to the list view only, as this is actually what we want. We don't care about "the last inserted block in the editor". We care about "the last block added to the list view component". This won't work because we only track the last inserted block. It's not a history stack. Therefore even if we could trigger an action that would update the state to say "hey this block(s) was inserted and it was from the offcanvas" it would be immediately lost if another call to Local Tracking State + Passing Context to lastInsertedBlockIdea: when I don't think this will work because the |
The Problem
It's unclear (without reading the code), why that Link UI would open anytime the component is mounted. It's due to a
useEffect
hook that opens the UI if:lastInsertedBlockId
These things are all still true when the component rerenders, so the Link UI shows again when it's mounted.
The Link UI also always shows when the first block in the navigation is missing a url, as the
lastInsertedBlockId
returns the first block in the array on load. I believe this is because on load it considers all the existing blocks as the last inserted blocks.How to Solve it
I believe the intention is that the LinkUI shows ONLY once when the link is added. If so, we can set a state to see if that UI has already shown or not, or set the useEffect as such that it only runs if the
lastInsertedBlockId
has changed.Test Reproduction Steps
The text was updated successfully, but these errors were encountered: