How to trigger a page refresh in the Admin UI after a Lifecycle Hook?

I am interested to know the answer as well, @dallasclark can you give this component a try?

import { useCMEditViewDataManager } from '@strapi/helper-plugin';
import React, { useEffect, useRef, useState } from 'react'
import { isEqual } from 'lodash/fp'

export const AfterUpdateReload = () => {
    const data = useCMEditViewDataManager()
    const { initialData, slug } = data;
    const [lastInitialData] = useState(initialData)
    const supportedSlug = ["api::product.product"]

    useEffect(() => {
        if(!supportedSlug.includes(slug ?? "")) return 
        if(isEqual(initialData, lastInitialData)) return

        window.location.reload()
    }, [initialData])

    return (
        <></>
    )
}
// ./src/admin/app.ts
import { AfterUpdateReload } from './extensions/AfterUpdateReload'

export default {
  config: {
    locales: [

    ],
    tutorials: false,
    notifications: { releases: false },
  },
  bootstrap(app) {
    app.injectContentManagerComponent("editView", "informations", {
      name: "my-compo",
      Component: AfterUpdateReload,
    });
  },
};

it works but definitely not ideal. It makes sense for Strapi not wait for result of afterUpdate by default, but it should be configurable. So webhook will cover async communication, and lifecycle hooks will cover sync communication with other systems

1 Like