Thanks for MVE, @helgatheviking! It was beneficial.
When wp.data
caches the resolvers, it also considers arguments. Here’s what happens when following the reproduction steps for the bug:
- Selecting the first product resolves data, creates a cache for
getProduct(1)
, and sets a value for theproduct
state. - Selecting second does the same (cache:
getProduct(2)
) and sets a new value for theproduct
state. - When switching back to the first product,
wp.data
knows the resolution was successful, so it calls the selector. The selector returns the latestproduct
state for Product #2 set in step 2.
Solution: Use product ID as key when storing them in state, so selectors return correct data. Here’s the updated fork – https://codesandbox.io/p/sandbox/mve-product-store-example-cached-resolve-value-forked-8lqv3r?file=%2Fsrc%2Fdata%2Findex.js.
P.S. You can check cached resolvers by running – select( storeName ).getCachedResolvers()
.
Related Posts:
- How to use wp.hooks.addAction() in React JS/Gutenberg?
- Extend core block in Gutenberg
- Hooking a callback into the code within a Gutenberg block
- What do the args for Gutenberg subpackage “hooks” function “doAction” mean?
- Use useSelect/useDispatch instead of withSelect/withDispatch
- How to use wp.hooks.addAction() in React JS/Gutenberg?
- useSelect second parameter
- Get terms of a taxonomy using useSelect
- Issue migrating a checkbox-type meta field to the block editor
- How to add more elements to an already existing section in Gutenberg
- Working with a non-React external library in a custom block
- Masonry gallery block is working in the block editor but not the template editor
- How to import the imagesLoaded and Masonry libs that come with WP in a Gutenberg block?
- Embedded data and the _fields parameter in getEntityRecords
- Force-update the meta variable first set using `var [ meta, setMeta = useEntityProp( ‘postType’, postType, ‘meta’ );`
- How to build BOTH non-block components and blocks present in the /src directory using @wordpress/scripts
- How to add an additional dependency to a block index.asset.php file
- Why is the Gutenberg editor not recognizing my updates?
- How to transform a shortcode into a block
- How to re-render Gutenberg component when object instance is available
- Trigger Javascript on Gutenberg (Block Editor) Save
- Set default image link target in Gutenberg image block
- Show control conditionally in Gutenberg
- How to get the ToggleControl Gutenberg component working for a PHP Block
- Is there a core Sortable component in Gutenberg?
- getEntityRecord without knowing the post type
- Is there an equivalent of the PHP function sanitize_key in Gutenberg?
- How to add extra attributes to the script tag added via wp_localize_script()
- How do I fire a snackbar notice in admin?
- Gutenberg Modify core taxonomy panel element via wp.hooks.addFilter
- What is “open()” in MediaUpload?
- Why is this gutenberg custom format button only available from the toolbar as a dropdown?
- Setting HTML properties in a Gutenberg plugin using WordPress settings
- Provide specific example for block variation
- Set current tab on a Gutenberg TabPanel component from outside that component
- Block editor: How to check if block editor has initialized and populated the data store?
- Gutenberg block “This block appears to have been modified externally” on save
- How to get value of selected page template in Gutenberg editor?
- @wordpress/components Button variants not styled
- Block Editor: How to get title and post content within the WordPress admin UI in Javascript?
- Gutenberg passing block attributes to component in ES6/ESNext
- Can the index.asset.php file be used with the enqueue_block_editor_assets action?
- How can I add Block Style support to the core HTML block in Gutenberg?
- var is undefined in a Gutenberg block
- Using wp.data.select get actual tags (not id’s) used in post
- can a buttongroup have a label?
- How to remove p / br elements from gutenbergs editor
- Programatically update posts in database from one block to another using transform
- InnerBlocks restricting does not work on nested blocks
- Gutenberg: Block validation Failed Richtext undefined
- Add custom HTML markup to Gutenberg RichText
- Listening change event of taxonomy term checkboxes in Gutenberg editor
- Gutenberg get core data – search
- Get Block Attributes in JSON REST API
- Open Featured Image Modal in WordPress Gutenberg onClick of a button
- How to add classes and events to image in javascript using Gutenberg?
- Checks when fetching data from multiple REST API endpoints in Gutenberg
- Add custom classes for blocks in editor based on custom attributes
- How to display post content in the block editor
- is_front_page() variable not found
- How can I allow HTML in Gutenberg UI elements help text?
- what is the purpose of the namespace argument when customizing blocks?
- Trigger wp-embed via JavaScript to refresh iframe preview?
- How can I import one custom block into another?
- Gutenberg Blocks: how to determine an index of the current inner block?
- Trying to turn the Edit function into a class to be able to use React lifecycle methods
- Gutenberg richtext block vaildation failed
- UnitControl – Block has encountered an error
- Gutenberg select excerpt, use generated excerpt or use more block excerpt
- Custom Gutenberg-Block esnext pass variables
- Building a Featured Gallery component for Gutenberg
- Gutenberg dependencies in package.json
- find out reason of “Updating failed” in Post-editor
- How to read inline-CSS from Gutenberg block?
- Gutenberg – useEffect manipulate DOM after block re-renders DOM
- Hook a script as the very last one before the closing body tag
- Problem extending a core block
- Cannot read properties of undefined (reading ‘show_ui’) Error on WordPress Post Editor
- Refresh Gutenberg with JS for it show updated post
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Gutenberg sidebar show input field on toggle
- Update block once an API request returns with a value
- Gutenberg – dynamically created element: how to set onChange?
- Call javascript function when add_attachment hook fires
- Custom block update rendering when reused
- WordPress Gutenberg Ajax request
- Gutenberg Edit Block Inspector Controls and save
- Spans in gutenberg
- Block pattern conflict with custom block
- WordPress Gutenberg: Attribute overwritten by block duplicate
- Where to include JS library in gutenberg blocks
- How to detect if we are in the Site Editor part of the Block Editor (as opposed to editing a Page/Post) in JavaScript?
- How can I show a Slot/Fill in the block editor
- Is it possible to add javascript to template parts
- How to add a new attribute to core wp block editor without npm?
- Create Youtube embed block with createBlock
- How to change the selected Template using javascript?
- Unable to trigger a frontend @wordpress/hooks action
- Cannot call a class as a function in block plugin react component
- useBlockProps() nests wrapper with class name inside block wrapper in the editor