Skip to content

Instantly share code, notes, and snippets.

@bkspace
bkspace / UntilLaidOut.tsx
Last active November 11, 2026 06:26
Stop Polaris <s-table> from shifting the page (CLS): hide it until it has its columns
import { useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react'
const subscribe = () => () => {}
/**
* Keeps its children hidden, and out of the page's flow, until every Polaris
* `s-table` in them has laid itself out. See README.md.
*
* Only what React mounts in the browser waits. Server-rendered HTML that React
* hydrates shows at once: hiding it would hold back the first paint.
@bkspace
bkspace / egress.ts
Last active October 28, 2026 07:24
egress.ts
import { shopifyApp, ... } from '@shopify/shopify-app-react-router/server'
import { setAbstractFetchFunc } from '@shopify/shopify-api/runtime'
import { env } from 'cloudflare:workers'
// Imports run before this module's body, so this overrides the
// web-api adapter's setAbstractFetchFunc(fetch).
setAbstractFetchFunc((input, init) => env.EGRESS.fetch(input, init))
{% liquid
assign discounts = shop.metafields.discount_kit.discount_information.value.discounts
assign current_date = 'now' | date: '%s' | times: 1
assign matched_config_ids = ""
for discount in discounts
assign config = discount.discountNode.config.value
assign starts_at = discount.startsAt | date: '%s' | times: 1
assign ends_at = discount.endsAt | date: '%s' | times: 1
cargo build --target wasm32-wasip1 --release
wasm-opt -Oz --output $1 $1 --enable-bulk-memory
@bkspace
bkspace / cart-upsell.liquid
Last active October 29, 2024 13:57
Discount Kit discount detection
{% liquid
assign discounts = shop.metafields.discount_kit.campaign.value.discounts
assign current_date = 'now' | date: '%s' | times: 1
# Initialize an array to store discount distances
assign discount_distances = ''
for discount in discounts
assign config = discount.discountNode.config.value
assign starts_at = discount.startsAt | date: '%s' | times: 1
@bkspace
bkspace / shopify-function-deploy.yml
Last active February 19, 2023 05:19
An example Github workflow file to deploy Shopify extensions/functions.
name: Function Deploy
on:
push:
branches:
- main
env:
SHOPIFY_API_KEY: ${{ secrets.SHOPIFY_API_KEY }}
SHOPIFY_FUNCTION_ID: ${{ secrets.SHOPIFY_FUNCTION_KEY }}
@bkspace
bkspace / Playground.hs
Created February 25, 2021 09:38
Plutus Playground Smart Contract
import qualified Data.Text as T
import Language.Plutus.Contract hiding (when)
import Language.PlutusTx.Prelude
import Playground.Contract
-- | A 'Contract' that logs a message.
hello :: Contract BlockchainActions T.Text ()
hello = logInfo @String "Hello, world"
endpoints :: Contract BlockchainActions T.Text ()
@bkspace
bkspace / RoutePropagator.tsx
Created October 14, 2020 14:54
Shopify admin route propagator
import { useEffect, useContext } from 'react'
import Router, { useRouter } from 'next/router'
import { Context as AppBridgeContext } from '@shopify/app-bridge-react'
import { Redirect } from '@shopify/app-bridge/actions'
import { RoutePropagator as ShopifyRoutePropagator } from '@shopify/app-bridge-react'
const RoutePropagator = () => {
const router = useRouter()
const { route } = router
const appBridge = useContext(AppBridgeContext)

Keybase proof

I hereby claim:

  • I am bkspace on github.
  • I am bkspace (https://keybase.io/bkspace) on keybase.
  • I have a public key ASCRTIorCsfX9NP_SzjocolxSC5M04diX9i0vhPVQOB1aAo

To claim this, I am signing this object: