Skip to content

Commit

Permalink
Catch invalid selector in FlatPage.svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Nov 20, 2023
1 parent eb4ae50 commit c5d1103
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/addons/dispatch/Selection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
bind:group={choice}
/>
{$_("addonDispatchDialog.labelSelected", {
values: { n: $layout.selected.length },
values: { n: $layout.selected?.length },
})}
</label>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/addons/dispatch/fields/ArrayField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
};
export let count: number = 1;
export let value = Array(count).fill(null);
$: numItems = value.length;
// only one level of nesting allowed
Expand Down
4 changes: 2 additions & 2 deletions src/api/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function searchDocumentsUrl(url) {

async function searchDocumentsHelper(url) {
const { data } = await session.get(url);
if (data.results.length > 0 && data.results[0].hasOwnProperty("document")) {
if (data.results?.length > 0 && data.results[0].hasOwnProperty("document")) {
// if we are using the project API, the document is one level down
data.results = filterDeleted(
data.results.map((doc) => new Document(doc.document)),
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function getDocumentsWithIds(
GET_BATCH,
GET_BATCH_DELAY,
async (subIds) => {
if (subIds.length == 0) return [];
if (subIds?.length == 0) return [];
// Return documents with the specified ids
const params = { expand, id__in: subIds };
if (remaining) params["remaining"] = true;
Expand Down
8 changes: 7 additions & 1 deletion src/pages/FlatPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
}
function navTo(hash, smooth = false) {
const elem = document.querySelector(hash);
let elem;
try {
elem = document.querySelector(hash);
} catch (error) {
elem = null;
}
if (elem) {
if (elem.scrollIntoView) {
elem.scrollIntoView({
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ This directory includes [Playwright](https://playwright.dev) tests that run in a
URL=https://www.dev.documentcloud.org npx playwright test
```

Netlify will automatically run this against any pull request using a deploy preview, and it will set the `URL` environment variable to the correct target.
Github will automatically run this against any pull request using a deploy preview, and it will set the `URL` environment variable to the correct target.

0 comments on commit c5d1103

Please sign in to comment.