Skip to content

Commit 22d3c02

Browse files
committed
add removeInactiveUnframerHiddenElements
1 parent fe2dd0c commit 22d3c02

File tree

7 files changed

+73
-51
lines changed

7 files changed

+73
-51
lines changed

unframer/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# unframer
22

3+
## 2.27.0
4+
5+
### Minor Changes
6+
7+
- Make .Responsive components much faster, delete them before React hydration
8+
9+
### Patch Changes
10+
11+
- 3661c24: Update to latest Framer runtime, [email protected], framer-motion@
12+
313
## 2.26.0
414

515
### Minor Changes

unframer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unframer",
3-
"version": "2.26.0",
3+
"version": "2.27.0",
44
"description": "Import Framer components directly in your React app, type safe and customizable",
55
"sideEffects": false,
66
"repository": "https://github.com/remorses/unframer",

unframer/src/css.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,44 +188,45 @@ export const breakpointsStylesLegacy = (breakpointSizes?: BreakpointSizes) => {
188188
export const breakpointsStyles = (breakpointSizes?: BreakpointSizes) => {
189189
breakpointSizes = { ...defaultBreakpointSizes, ...breakpointSizes }
190190
return /* css */ `
191+
191192
/* Base */
192193
@media (min-width: ${breakpointSizes.base}px) and (max-width: ${breakpointSizes.sm - 1}px) {
193-
.unframer:not(.unframer-base) {
194+
.unframer-hidden:not(.unframer-base) {
194195
display: none !important;
195196
}
196197
}
197198
198199
/* Small */
199200
@media (min-width: ${breakpointSizes.sm}px) and (max-width: ${breakpointSizes.md - 1}px) {
200-
.unframer:not(.unframer-sm) {
201+
.unframer-hidden:not(.unframer-sm) {
201202
display: none !important;
202203
}
203204
}
204205
205206
/* Medium */
206207
@media (min-width: ${breakpointSizes.md}px) and (max-width: ${breakpointSizes.lg - 1}px) {
207-
.unframer:not(.unframer-md) {
208+
.unframer-hidden:not(.unframer-md) {
208209
display: none !important;
209210
}
210211
}
211212
212213
/* Large */
213214
@media (min-width: ${breakpointSizes.lg}px) and (max-width: ${breakpointSizes.xl - 1}px) {
214-
.unframer:not(.unframer-lg) {
215+
.unframer-hidden:not(.unframer-lg) {
215216
display: none !important;
216217
}
217218
}
218219
219220
/* Extra Large */
220221
@media (min-width: ${breakpointSizes.xl}px) and (max-width: ${breakpointSizes['2xl'] - 1}px) {
221-
.unframer:not(.unframer-xl) {
222+
.unframer-hidden:not(.unframer-xl) {
222223
display: none !important;
223224
}
224225
}
225226
226227
/* 2 Extra Large */
227228
@media (min-width: ${breakpointSizes['2xl']}px) {
228-
.unframer:not(.unframer-2xl) {
229+
.unframer-hidden:not(.unframer-2xl) {
229230
display: none !important;
230231
}
231232
}

unframer/src/exporter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ export async function bundle({
468468
resetCssStyles +
469469
getStyleTokensCss(tokens || []) +
470470
breakpointsStyles(breakpoints) +
471-
breakpointsStylesLegacy(breakpoints) +
472471
'\n\n' +
473472
combinedCSSRules
474473
.map((x) => (x?.startsWith(' ') ? dedent(x) : x))

unframer/src/framer.js

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11214,14 +11214,15 @@ function stagger(duration = 0.1, {
1121411214
};
1121511215
}
1121611216

11217-
// /:https://app.framerstatic.com/framer.QUUNUZCV.mjs
11217+
// /:https://app.framerstatic.com/framer.6RBAH774.mjs
1121811218
import { lazy as ReactLazy, } from 'react';
1121911219
import React4 from 'react';
1122011220
import { startTransition as startTransition2, } from 'react';
1122111221
import { Suspense as Suspense2, } from 'react';
1122211222
import { memo as memo2, } from 'react';
1122311223
import ReactDOM from 'react-dom';
1122411224
import { createRef, } from 'react';
11225+
import { useTransition, } from 'react';
1122511226
import { cloneElement as cloneElement32, } from 'react';
1122611227
var __unframerNavigator2 = typeof window !== 'undefined' ? navigator : void 0;
1122711228
var require_hsluv = __commonJS({
@@ -42299,62 +42300,44 @@ function getWhereExpressionFromPathVariables(pathVariables, collection,) {
4229942300
}));
4230042301
}
4230142302
function useLoadMorePagination(totalSize, pageSize, hash2, paginateWithSuspendedLoadingState = false,) {
42303+
var _a, _b, _c, _d;
42304+
const [isPending, startLoadingTransition,] = useTransition();
4230242305
const totalPages = Math.ceil(totalSize / pageSize,);
42303-
const [paginationInfo, setPaginationInfo,] = useState(() => {
42304-
var _a, _b, _c, _d;
42305-
const currentPage = ((_d = (_c = (_b = (_a = globalThis == null ? void 0 : globalThis.history) == null ? void 0 : _a.state) == null
42306+
const [currentPage, setCurrentPage,] = useState(
42307+
((_d = (_c = (_b = (_a = globalThis == null ? void 0 : globalThis.history) == null ? void 0 : _a.state) == null
4230642308
? void 0
4230742309
: _b.paginationInfo) == null
4230842310
? void 0
4230942311
: _c[hash2]) == null
4231042312
? void 0
42311-
: _d.currentPage) ?? 1;
42313+
: _d.currentPage) ?? 1,
42314+
);
42315+
const paginationInfo = useMemo2(() => {
4231242316
return {
4231342317
currentPage,
4231442318
totalPages,
42315-
isLoading: false,
42319+
isLoading: isPending,
4231642320
};
42317-
},);
42318-
useEffect(() => {
42319-
startTransition2(() => {
42320-
setPaginationInfo((current2) => {
42321-
if (current2.totalPages === totalPages) return current2;
42322-
return {
42323-
...current2,
42324-
totalPages,
42325-
};
42326-
},);
42327-
},);
42328-
}, [totalPages,],);
42321+
}, [currentPage, totalPages, isPending,],);
4232942322
useEffect(() => {
4233042323
pushLoadMoreHistory(hash2, paginationInfo,);
4233142324
}, [hash2, paginationInfo,],);
4233242325
const onCanvas = useIsOnFramerCanvas();
42333-
const loadMore = useCallback(() => {
42326+
const loadMore = useCallback(async () => {
4233442327
if (onCanvas) return;
42335-
if (paginationInfo.currentPage >= paginationInfo.totalPages) return;
42336-
if (!paginateWithSuspendedLoadingState) {
42337-
startTransition2(() => {
42338-
setPaginationInfo((info) => ({
42339-
...info,
42340-
currentPage: Math.min(info.currentPage + 1, info.totalPages,),
42341-
isLoading: false,
42342-
}));
42343-
},);
42344-
return;
42345-
}
42346-
setPaginationInfo((info) => ({
42347-
...info,
42348-
isLoading: true,
42349-
}));
42350-
requestAnimationFrame(() => {
42351-
setPaginationInfo((info) => ({
42352-
...info,
42353-
currentPage: Math.min(info.currentPage + 1, info.totalPages,),
42354-
isLoading: false,
42355-
}));
42328+
if (currentPage >= totalPages) return;
42329+
await yieldToMain({
42330+
priority: 'user-blocking',
42331+
continueAfter: 'paint',
4235642332
},);
42357-
}, [onCanvas, paginationInfo.currentPage, paginationInfo.totalPages, paginateWithSuspendedLoadingState,],);
42333+
const renderNextPage = (startTransition14) => {
42334+
startTransition14(() => {
42335+
setCurrentPage((_currentPage) => Math.min(_currentPage + 1, totalPages,));
42336+
},);
42337+
};
42338+
if (!paginateWithSuspendedLoadingState) return renderNextPage(startTransition2,);
42339+
return renderNextPage(startLoadingTransition,);
42340+
}, [currentPage, totalPages, paginateWithSuspendedLoadingState,],);
4235842341
return {
4235942342
paginationInfo,
4236042343
loadMore,
@@ -42845,6 +42828,11 @@ function tryToApplyOverride(Component17, override,) {
4284542828
function valueWithMirroring(value, mirror,) {
4284642829
return mirror ? wrap(0, 2, value,) : value;
4284742830
}
42831+
function singleFrame() {
42832+
return new Promise((resolve) => {
42833+
frame.postRender(() => resolve());
42834+
},);
42835+
}
4284842836
var withV1StrokeFX = (Component17) =>
4284942837
forwardRef((props, forwardedRef,) => {
4285042838
const {
@@ -42876,7 +42864,7 @@ var withV1StrokeFX = (Component17) =>
4287642864
const mirror = strokeEffectLoop && strokeEffectLoopType === 'mirror';
4287742865
const from = valueWithMirroring(index, mirror,);
4287842866
const to = valueWithMirroring(index + 1, mirror,);
42879-
await animate(offset, [from, to,], pathLengthTransition,);
42867+
await Promise.all([animate(offset, [from, to,], pathLengthTransition,), singleFrame(),],);
4288042868
if (!strokeEffectLoop) break;
4288142869
if (strokeEffectLoop && strokeEffectLoopType === 'repeat') continue;
4288242870
index++;

unframer/src/react.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { version } from './version.js'
2121
function classNames(...args) {
2222
return args.filter(Boolean).join(' ')
2323
}
24+
2425
function Hints() {
2526
prefetchDNS('https://fonts.gstatic.com')
2627
preconnect('https://fonts.gstatic.com')
@@ -118,6 +119,29 @@ export function FramerStyles({ Components = [] as any[] }): any {
118119
</>
119120
)
120121
}
122+
function removeInactiveUnframerHiddenElements() {
123+
// Remove all elements with the 'unframer-hidden' class that are not for the current breakpoint
124+
const windowWidth = window.innerWidth
125+
const activeBreakpoint = getBreakpointNameFromWindowWidth(windowWidth)
126+
const activeClass = activeBreakpoint ? `unframer-${activeBreakpoint}` : null
127+
128+
console.log('Active unframer breakpoint class:', activeClass)
129+
130+
document.querySelectorAll('.unframer-hidden').forEach((el) => {
131+
// Merge: Only remove the element itself if it has 'unframer-hidden' and does not match the current breakpoint's class.
132+
if (
133+
el.classList.contains('unframer-hidden') &&
134+
activeClass &&
135+
!el.classList.contains(activeClass)
136+
) {
137+
el.parentNode?.removeChild(el)
138+
}
139+
})
140+
}
141+
142+
if (typeof window !== 'undefined') {
143+
removeInactiveUnframerHiddenElements()
144+
}
121145

122146
export const WithFramerBreakpoints = <
123147
T extends ComponentType<{ variant?: any; className?: string }>,

unframer/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const version = '2.26.0'
1+
export const version = '2.27.0'

0 commit comments

Comments
 (0)