Skip to content

Commit

Permalink
fix(behavior): set fallback target (#1089)
Browse files Browse the repository at this point in the history
In the original implementation, the original `element` was the fallback
target. In cases where a `targetId` is specified but unfound, we can
still fall back to the original element.

Relates to #1068

| Before | After |
| -- | -- |
|
![before](https://github.com/user-attachments/assets/7310c5e1-ed69-46ed-a5f3-23dd5aace305)
|
![after](https://github.com/user-attachments/assets/511d6155-7fdb-4f52-97c3-97cf44db580a)
|

An error is being logged to notify developers

| | |
| -- | -- |
|
![error-closed](https://github.com/user-attachments/assets/35578e01-d656-4fa1-83be-9e227fdb340c)
|
![error-open](https://github.com/user-attachments/assets/d7850c85-9ac8-4b9a-a38b-0daf5655925a)
|



[Asana](https://app.asana.com/0/1204008699308084/1209438247623833)
  • Loading branch information
hgray-instawork authored Feb 19, 2025
1 parent c68b62f commit cc13bff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/core/components/hv-root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ export default class Hyperview extends PureComponent<Types.Props> {
onUpdateCallbacks.getDoc(),
behaviorElement,
);
// Warn developers if a provided target was not found
if (targetId) {
Logging.error(
'Target element not found. Falling back to current element.',
{ id: targetId },
);
}
}

if (newElement && targetElement) {
Expand Down
9 changes: 3 additions & 6 deletions src/services/dom/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,9 @@ export const processDocument = (doc: Document): Document => {
const action = behavior.getAttribute('action');
const updateAction: UpdateAction = action as UpdateAction;
if (updateAction && Object.values(UPDATE_ACTIONS).includes(updateAction)) {
const target = behavior.getAttribute('target');
if (!target) {
const behaviorId = behavior.getAttribute('id');
if (!behaviorId) {
behavior.setAttribute('id', uuid());
}
const behaviorId = behavior.getAttribute('id');
if (!behaviorId) {
behavior.setAttribute('id', uuid());
}
}
});
Expand Down

0 comments on commit cc13bff

Please sign in to comment.