mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix(component): lit portal not re-rendering in inline links case (#9321)
* uses `portal.key` in templates * updates `portal.id` for use in queries
This commit is contained in:
@@ -2,4 +2,4 @@ export {
|
||||
type ElementOrFactory,
|
||||
useLitPortal,
|
||||
useLitPortalFactory,
|
||||
} from './lite-portal';
|
||||
} from './lit-portal';
|
||||
|
||||
@@ -13,10 +13,9 @@ type PortalEvent = {
|
||||
type PortalListener = (event: PortalEvent) => void;
|
||||
|
||||
export function createLitPortalAnchor(callback: (event: PortalEvent) => void) {
|
||||
const id = nanoid();
|
||||
return html`<lit-react-portal
|
||||
.notify=${callback}
|
||||
portalId=${id}
|
||||
portalId=${nanoid()}
|
||||
></lit-react-portal>`;
|
||||
}
|
||||
|
||||
@@ -119,24 +118,27 @@ export const useLitPortalFactory = () => {
|
||||
}
|
||||
|
||||
const prevId = event.previousPortalId;
|
||||
// Ignore first `willUpdate`
|
||||
if (!prevId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No re-rendering allowed
|
||||
// Used in `pdf embed view` scenario
|
||||
if (!rerendering) {
|
||||
// Ignores first `willUpdate`
|
||||
if (!prevId) {
|
||||
return;
|
||||
}
|
||||
|
||||
setPortals(portals => {
|
||||
const portal = portals.find(p => p.id === prevId);
|
||||
if (!portal) return portals;
|
||||
if (!portal) return [...portals];
|
||||
|
||||
// Updates `ID`
|
||||
// Used for portal queries in `disconnectedCallback`
|
||||
portal.id = id;
|
||||
portal.portal.key = id;
|
||||
portal.portal.children = element;
|
||||
|
||||
// Re-rendering
|
||||
// true: `inline link`
|
||||
// false: `pdf embed view`
|
||||
if (rerendering) {
|
||||
portal.portal = ReactDOM.createPortal(element, target, id);
|
||||
}
|
||||
|
||||
return [...portals];
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user