Skip to content

fix(dismissable-layer): guard isTopMostLayer against empty layers array#650

Open
EduardF1 wants to merge 2 commits into
kobaltedev:mainfrom
EduardF1:fix/dismissable-layer-empty-stack
Open

fix(dismissable-layer): guard isTopMostLayer against empty layers array#650
EduardF1 wants to merge 2 commits into
kobaltedev:mainfrom
EduardF1:fix/dismissable-layer-empty-stack

Conversation

@EduardF1

@EduardF1 EduardF1 commented May 4, 2026

Copy link
Copy Markdown

Problem

isTopMostLayer crashes with TypeError when layers array is empty.

Root cause

layers[layers.length - 1].node throws when layers is empty, since layers[-1] is undefined. Can happen during teardown or before a layer is registered.

Fix

Add a length guard:

function isTopMostLayer(node: HTMLElement | null) {
  return layers.length > 0 && layers[layers.length - 1].node === node;
}
```n
Returning `false` for an empty stack is correct  no layer is on top.

Fixes #649

@netlify

netlify Bot commented May 4, 2026

Copy link
Copy Markdown

👷 Deploy request for kobalte pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7eadb77

@jer3m01

jer3m01 commented May 18, 2026

Copy link
Copy Markdown
Member

Thanks for the fix! Will get this for release this week.

@EduardF1

Copy link
Copy Markdown
Author

Summary

Adds a one-line defensive guard to isTopMostLayer to handle an empty layers array, fixing a crash that occurs after programmatically closing the last dismissable layer (fixes #649).

Status

  • CI: ✅ No unresolved review threads
  • Narrowly scoped — no behavior change in the happy path
  • Ready for review

@jer3m01 happy to rebase or adjust the guard/test placement if needed. Thanks!

@EduardF1

Copy link
Copy Markdown
Author

Thanks @jer3m01, appreciate it. If it helps before release, I can also add a tiny regression test around the empty-stack case, but I kept the patch minimal since the fix is just the defensive length guard.

@EduardF1

EduardF1 commented Jun 1, 2026

Copy link
Copy Markdown
Author

@jer3m01 friendly check-in on the release timing for this. If a patch-version bump or a CHANGELOG entry would help unblock cutting it, happy to push that in a follow-up commit.

@EduardF1

EduardF1 commented Jun 4, 2026

Copy link
Copy Markdown
Author

Hi team, gentle ping — CI is green and the change is small. Would appreciate a review when you get a chance! 🙏

@EduardF1

EduardF1 commented Jun 4, 2026

Copy link
Copy Markdown
Author

Hi team, checking in on this PR! Let me know if you have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants