IntersectionObserver
turbo
IntersectionObserver | turbo | |
---|---|---|
6 | 57 | |
3,621 | 24,977 | |
0.1% | 1.3% | |
5.0 | 9.9 | |
about 2 months ago | 5 days ago | |
Bikeshed | Rust | |
GNU General Public License v3.0 or later | Mozilla Public License 2.0 |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
IntersectionObserver
-
Lazy loading of images in masonry layout?
You should only create the images (or set the src) for the images which are visible to the user. See our infinite scroll example for a naive implementation. More elaborated code might use the https://www.w3.org/TR/intersection-observer/.
-
Safari isn't protecting the web, it's killing it
I got a little curious on the statuses of these standards and went on a bit of searching.
> CSS contain (CSS Containment Module Level 2) - First published in 2019, still Editor's Draft[1]. Not supported by Safari/WebKit.
> CSS offset-path (Motion Path Module Level 1) - First published in 2015, still Editor's Draft[2]. Not supported by Safari/WebKit.
> CSS overflow-anchor (CSS Scroll Anchoring Module Level 1) - First published in 2020, still Editor's Draft[3]. Not supported by Safari/WebKit.
> Resolution media queries (dppx) - W3C Recommendation since 2012[4]. Not supported by Safari/WebKit.
> :focus-visible (Selectors Level 4) - First published in 2011, still Editor's Draft[5]. Not supported by Safari/WebKit.
- Touch Events - W3C Recommendation since 2013[6]. Supported on iOS 3.2 (2010). I assume the author meant Pointer Events[7] which became W3C recommendation since 2019, and supported on 13.2 (2019).
> BroadcastChannel - WHATWG Living Standard[8]. Blocked by privacy concern on WebKit side since 2020[9]. Initial support landed in WebKit trunk as of 2021-07.[10]
> beforeprint/afterprint - WHATWG Living Standard[11]. Supported by Safari/WebKit since 2019 (iOS 13).
> Regex Lookbehind - ECMAScript 2018[12]. Not supported by Safari/WebKit.
> scrollIntoView (CSSOM View Module) - First introduced in CSSOM View Module since 2011, still Editor's Draft[13]. Not supported by Safari/WebKit.
> Screen Orientation API - First committed in wc3/screen-orientation in 2012, still a W3C Working Draft[14]. Not supported by Safari/WebKit.
> Date and time input types - WHATWG Living Standard[15], partial support by Safari/WebKit since 2012 (iOS 5) but no week/min/max.
> Service Workers - W3C Candidate Recommendation since 2019[16]. Supported by Safari/WebKit since 2018 (iOS 14.5).
- AbortSignal - WHATWG Living Standard[17]. Supported by Safari/WebKit since 2018 (iOS 11.3)
- Intersection Observer - First published in 2017, still W3C Working Draft[18]. Supported by Safari/WebKit since 2019 (iOS 12.2).
- Client-side form validation - WHATWG Living Standard[19]. Supported by Safari/WebKit since 2017 (iOS 10.3).
[1]: https://drafts.csswg.org/css-contain/#contain-property
[2]: https://drafts.fxtf.org/motion/#offset-path-property
[3]: https://drafts.csswg.org/css-scroll-anchoring/#exclusion-api
[4]: https://www.w3.org/TR/css3-mediaqueries/#resolution
[5]: https://drafts.csswg.org/selectors-4/#the-focus-visible-pseu...
[6]: https://www.w3.org/TR/touch-events/
[7]: https://www.w3.org/TR/pointerevents/
[8]: https://html.spec.whatwg.org/multipage/web-messaging.html#br...
[9]: https://github.com/whatwg/html/issues/5803
[10]: https://bugs.webkit.org/show_bug.cgi?id=227924
[11]: https://html.spec.whatwg.org/multipage/timers-and-user-promp...
[12]: https://262.ecma-international.org/9.0/
[13]: https://drafts.csswg.org/cssom-view/#dom-element-scrollintov...
[14]: https://www.w3.org/TR/screen-orientation/
[15]: https://html.spec.whatwg.org/multipage/input.html#date-state...
[16]: https://www.w3.org/TR/service-workers/
[17]: https://dom.spec.whatwg.org/#abortsignal
[18]: https://www.w3.org/TR/intersection-observer/
[19]: https://html.spec.whatwg.org/multipage/forms.html#client-sid...
-
Revealing Contents on Scroll Using JavaScript’s Intersection Observer API
W3.Org
-
Adding IntersectionObserver polyfill
I've used https://github.com/w3c/IntersectionObserver/tree/main/polyfill in the past and it's pretty much just import and forget.
-
Endless Scroll / Infinite Loading with Turbo Streams & Stimulus
// app/javascript/controllers/infinite_scoll_controller.js import { Controller } from "stimulus" export default class extends Controller { static targets = ["scrollArea", "pagination"] connect() { this.createObserver() } createObserver() { const observer = new IntersectionObserver( entries => this.handleIntersect(entries), { // https://github.com/w3c/IntersectionObserver/issues/124#issuecomment-476026505 threshold: [0, 1.0], } ) observer.observe(this.scrollAreaTarget) } handleIntersect(entries) { entries.forEach(entry => { if (entry.isIntersecting) { this.loadMore() } }) } loadMore() { const next = this.paginationTarget.querySelector("[rel=next]") if (!next) { return } const href = next.href fetch(href, { headers: { Accept: "text/vnd.turbo-stream.html", }, }) .then(r => r.text()) .then(html => Turbo.renderStreamMessage(html)) .then(_ => history.replaceState(history.state, "", href)) } }
-
Create an infinite scrolling blog roll in Rails with Hotwire
import { Controller } from "stimulus" export default class extends Controller { static targets = ["entry"] static values = { path: String, } connect() { this.createObserver(); } createObserver() { let observer; let options = { // https://github.com/w3c/IntersectionObserver/issues/124#issuecomment-476026505 threshold: [0, 1.0] }; observer = new IntersectionObserver(entries => this.handleIntersect(entries), options); observer.observe(this.entryTarget); } handleIntersect(entries) { entries.forEach(entry => { if (entry.isIntersecting) { // https://github.com/turbolinks/turbolinks/issues/219#issuecomment-376973429 history.replaceState(history.state, "", this.pathValue); } }); } }
turbo
-
Supermemory - ChatGPT for your bookmarks
Supermemory has three main modules, managed by turborepo:
-
Next.js Shopify eCommerce Starter with Perfect Web Vitals 🚀
From a structural viewpoint, we use a monorepo (Turborepo) to manage packages, even though we currently have only one Next.js app. We chose this setup because it prepares us for future developments, which will include additional apps. This arrangement helps keep the packages well-separated and self-contained.
-
dev.to wrapped 2023 🎁
# src Dockerfile: https://github.com/vercel/turbo/blob/main/examples/with-docker/apps/web/Dockerfile FROM node:18-alpine AS alpine # setup pnpm on the alpine base FROM alpine as base ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable RUN pnpm install turbo --global FROM base AS builder # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat RUN apk update # Set working directory WORKDIR /app COPY . . RUN turbo prune --scope=web --docker # Add lockfile and package.json's of isolated subworkspace FROM base AS installer RUN apk add --no-cache libc6-compat RUN apk update WORKDIR /app # First install the dependencies (as they change less often) COPY .gitignore .gitignore COPY --from=builder /app/out/json/ . COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml RUN pnpm install # Build the project COPY --from=builder /app/out/full/ . COPY turbo.json turbo.json RUN turbo run build --filter=web # use alpine as the thinest image FROM alpine AS runner WORKDIR /app # Don't run production as root RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs USER nextjs COPY --from=installer /app/apps/web/next.config.js . COPY --from=installer /app/apps/web/package.json . # Automatically leverage output traces to reduce image size # https://nextjs.org/docs/advanced-features/output-file-tracing COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./ COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public CMD node apps/web/server.js
-
.dockerignore being ignored by docker-compose? no space left on device
Following this example: https://github.com/vercel/turbo/tree/main/examples/with-docker/apps/web. Except I'm using pnpm. Edit Reddit Codeblocks are horrible and keeps removing all formatting.
-
How to Win Any Hackathon 🚀🤑
The Dockerfile might seem a bit complicated (it is), but the reason for that is mostly just turborepo and the need for good caching. Realistically, you will only need to change the last line, if at all. It is based on this awesome Github Issue.
-
PURISTA: Build with rimraf, esbuild, Turbo & git-cliff
PURISTA is organized in a monorepo. During the development and build process, Turbo is used to execute different tasks and steps on multiple packages with one command.
-
How I approach and structure Enterprise frontend applications after 4 years of using Next.js
Turbo repo
-
Vercel Integration and Next.js App Router Support
Previously we mapped each Vercel project to a single Supabase project. With this release, we're introducing the concept of project 'Connections'. Supabase projects can have an unlimited number of Vercel Connections. This is especially useful for monorepos using Turborepo.
-
How Turborepo is porting from Go to Rust
One detail I enjoy from this post is that sometimes you can just call a CLI[0]. It's easy to spend a lot of time figuring out how to expose some Rust/C code as a library for your language, but I like the simplicity of just compiling, shipping the binary and then calling it as a subprocess.
Yes, there's overhead in starting a new process to "just call a function", but I think this approach is still underutilized.
[0]: https://github.com/vercel/turbo/blob/c0ee0dea7388d1081512c93...
- App Router example repos