Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use org name in header #143

Merged
merged 12 commits into from
Oct 31, 2024
Merged

Conversation

zugdev
Copy link
Contributor

@zugdev zugdev commented Oct 30, 2024

Resolves #141

This pulls from #140 so merge it first.

Check the video:

org-label.mp4

Also am not sure if we should keep DEVPOOL always? Lmk

@zugdev zugdev requested a review from 0x4007 as a code owner October 30, 2024 03:34
@ubiquity-os-deployer
Copy link

ubiquity-os-deployer bot commented Oct 30, 2024

.gitignore Show resolved Hide resolved
src/home/rendering/render-org-header.ts Outdated Show resolved Hide resolved
@@ -14,75 +14,87 @@ const urlsToCache = [
// Install event (caches all necessary files)
self.addEventListener("install", (event) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async this instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this? self.addEventListener("install", async (event) => { not sure why though

@0x4007
Copy link
Member

0x4007 commented Oct 30, 2024

Resolves #141

This pulls from #140 so merge it first.

Check the video:

org-label.mp4

Also am not sure if we should keep DEVPOOL always? Lmk

I'm not sure either so let's leave it for now and change later if we need to.

We have the domain name devpool.directory/ubiquity etc so it makes sense to still reference it.

It would be interesting to

  1. Have orgs cname the domain to "host" on their own domains
  2. Dynamically generate the color theme based on their org avatar but seems difficult hard to do well, and isn't a priority so I think we can't fund that research.

@zugdev
Copy link
Contributor Author

zugdev commented Oct 30, 2024

It would be interesting to

  1. Have orgs cname the domain to "host" on their own domains

I have that in mind, yes.

  1. Dynamically generate the color theme based on their org avatar but seems difficult hard to do well, and isn't a priority so I think we can't fund that research.

This is very cool and is not that hard tbh. We could create an issue with low priority and re-label it when the right time comes.

statusText: "Internal Server Error",
});
}
})()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange that you do self invoking functions to do async. Just wrap the entire callback inside an async function like we discussed here and then you can await them like normal.

Also change catch to try catch. And don't use thenable, use async await.

Copy link
Contributor Author

@zugdev zugdev Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self invoking functions are needed because event's waitUntil() method receives a promise as a parameter - not a function that returns a promise, (see reference). I can only imagine that your idea was to remore the use of waitUntil entirely, for instance:

// Install event (caches all necessary files)
self.addEventListener("install", async (event) => {
  try {
    const cache = await caches.open(cacheName);
    await cache.addAll(urlsToCache);
    console.log("[Service Worker] Files cached successfully");
  } catch (error) {
    console.error("[Service Worker] Cache failed:", error);
  }
  self.skipWaiting(); // Activate the new worker immediately
});

instead of:

// Install event (caches all necessary files)
self.addEventListener("install", async (event) => {
  event.waitUntil(
    (async () => {
      try {
        const cache = await caches.open(cacheName);
        await cache.addAll(urlsToCache);
        console.log("[Service Worker] Files cached successfully");
      } catch (error) {
        console.error("[Service Worker] Cache failed:", error);
      }
      self.skipWaiting(); // Activate the new worker immediately
    })()
  );
});

The difference between these approaches is that with waitUntil() adding assets to cache becomes an asynchronous task, which would allow the task to be completed even after returning inside the event handler. During install this is not a problem, however in a fetch event I want the service worker to return whatever is in cache, but fire an asynchronous task to update the cache with a network response. If we remove waitUntil() and just await the network response, we would have to wait for network response to return whatever is in cache, seriously compromising speed in very slow networks.

Here is a QA using waitUntil() to return from cache and asynchronously update cache with network response, in a simulated 10kbps network speed:

10kbps-network.webm

Here is a QA awaiting the network response, in a simulated 10kbps network speed:

10kbps-network-await.webm

Here are some additional references to clarify:

What does event.waitUntil do in service worker and why is it needed?

JavaScript how to use event.waitUntil() to wait for an async function call

Should I use event.waitUntil() or await fetch() or just fetch()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay seems like you did your research so let's do what you think is right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was good feedback, it's very important that we understand each others code practices, as well as document weird patterns. Thanks.

@zugdev
Copy link
Contributor Author

zugdev commented Oct 31, 2024

Can we merge #140 and then this one (#143)?

@zugdev zugdev changed the title Use org label feat: use org name in header Oct 31, 2024
@0x4007
Copy link
Member

0x4007 commented Oct 31, 2024

Can we merge #140 and then this one (#143)?

I don't think order should matter git is supposed to handle this

@0x4007 0x4007 merged commit c4d5b58 into ubiquity:development Oct 31, 2024
1 of 2 checks passed
@ubiquity-os ubiquity-os bot mentioned this pull request Nov 1, 2024
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.

White Labeling Header
2 participants