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 theproductstate. - Selecting second does the same (cache:
getProduct(2)) and sets a new value for theproductstate. - When switching back to the first product,
wp.dataknows the resolution was successful, so it calls the selector. The selector returns the latestproductstate 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?
- 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
- Gutenberg DatePicker component with time set to zero
- How to render HTML content using the Interactivity API?
- How to auto rename JS files to prevent browser cache issues
- How to render initial posts on page load in a Gutenberg block using the Interactivity API?
- How to include block style variations for blocks in posts dynamically rendered via the Interactivity API
- Set default image link target in Gutenberg image block
- What are all the query parameters for getEntityRecords?
- How to only enqueue block javascript on the frontend when its needed [duplicate]
- Get loading state of wp data selector
- Is there a core Sortable component in Gutenberg?
- 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()
- Correctly handling WordPress core data retrieval in Gutenberg
- Is there a client side API for handling transients or options?
- Gutenberg Modify core taxonomy panel element via wp.hooks.addFilter
- What is “open()” in MediaUpload?
- Adding a text element in between title and blocks container
- Setting HTML properties in a Gutenberg plugin using WordPress settings
- Gutenberg RichText
- 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?
- Custom block SelectControl works but equivalent ComboboxControl gives errors – where’s my mistake?
- How can I add Block Style support to the core HTML block in Gutenberg?
- event/callback on block update?
- can a buttongroup have a label?
- How to disable inline css styles generated by Gutenberg editor?
- Gutenberg getMedia() in post query doesn’t return all featured images
- InnerBlocks restricting does not work on nested blocks
- Gutenberg: Block validation Failed Richtext undefined
- Add A Tag To A Post Through JavaScript In Gutenberg UI?
- Add custom HTML markup to Gutenberg RichText
- Adding nonce or hashes to inline scripts
- How to return div with custom attributes(Coding a Gutenberg Block)
- Open MediaUpload from external component in Gutenberg
- Get Block Attributes in JSON REST API
- Open Featured Image Modal in WordPress Gutenberg onClick of a button
- 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?
- Gutenberg consume wp-json data and reflect in frontend the content
- How can I import one custom block into another?
- Gutenberg Blocks: how to determine an index of the current inner block?
- UnitControl – Block has encountered an error
- Gutenberg select excerpt, use generated excerpt or use more block excerpt
- Building a Featured Gallery component for Gutenberg
- Gutenberg dependencies in package.json
- find out reason of “Updating failed” in Post-editor
- Gutenberg RangeControl
- 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
- Add a Page Screen is Visually Blank
- 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
- Get the ID of a page in Parent combobox in editor
- 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
- Gutenberg Edit Block Inspector Controls and save
- Spans in gutenberg
- WordPress Gutenberg: Attribute overwritten by block duplicate
- How to delete child block for associated parent block
- Passing object to FormTokenField suggestions
- Use add_action to run a script, but only on the post editor page
- How do i get an Inline style in Gutenberg Block show up in front end?
- WordPress adds and tags into HTML blocks after saving
- How do i fix type error
- Gutenberg core/file add style support in js/ json
- Create Youtube embed block with createBlock
- How to add a css class to postTitleWrapper in Gutenberg?
- How to use useSelect to retrieve the currently default fontFamily?
- Event when Modal is opened/visible
- Additional CSS classes not being added in Gutenberg editor
- How do I filter/modify the updated content on save using javascript?
- How to execute some javascript code in the editor when a block pattern is added?
- useBlockProps() nests wrapper with class name inside block wrapper in the editor
- How to access current discussion settings in gutenberg via JS?