fix(fuc): preserve loaded styles during native page transitions
Keep common LINK nodes attached, load ordered mode styles and overrides before committing the next page, and avoid reparenting dark/bridge styles. Bump Fuc to 0.12.3.
This commit is contained in:
1 parent
f236c58935
commit
2022184583
10 files changed
+67
-32
No files matched your search
@@ -30,6 +30,8 @@ globalThis.fetch=async(url,options={})=>{
|
||||
};
|
||||
const append=document.head.append.bind(document.head);
|
||||
document.head.append=node=>{append(node);if(node.tagName==='SCRIPT')queueMicrotask(()=>{try{window.eval(requireFile(node.src));node.onload?.();}catch(error){node.onerror?.(error);}});if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());};
|
||||
const insertBefore=document.head.insertBefore.bind(document.head);
|
||||
document.head.insertBefore=(node,before)=>{const result=insertBefore(node,before);if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());return result;};
|
||||
const {readFileSync}=await import('node:fs');const requireFile=url=>readFileSync(new URL(url),'utf8');
|
||||
const until=async predicate=>{for(let n=0;n<200;n++){if(predicate())return;await new Promise(resolve=>setTimeout(resolve,10));}throw Error('DOM state did not settle');};
|
||||
const go=async route=>{location.hash='/'+route;await until(()=>document.body.dataset.nativePage===route);};
|
||||
|
||||
@@ -10,6 +10,28 @@ const {paymentForm,showPayment}=await import('../../theme/Fuc/assets/payments.mj
|
||||
const {richText}=await import('../../theme/Fuc/assets/content.mjs');
|
||||
const {copyText}=await import('../../theme/Fuc/assets/clipboard.mjs');
|
||||
const native=await import('../../theme/Fuc/assets/native.mjs');await native.nativeReady;
|
||||
test('user navigation keeps active shared CSS and its dark/bridge overrides attached',async()=>{
|
||||
const append=document.head.append.bind(document.head),insert=document.head.insertBefore.bind(document.head),moved=[];
|
||||
document.head.append=node=>{if(node.isConnected&&node.tagName==='LINK')moved.push(node);append(node);if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());};
|
||||
document.head.insertBefore=(node,before)=>{if(node.isConnected&&node.tagName==='LINK')moved.push(node);const result=insert(node,before);if(node.tagName==='LINK')queueMicrotask(()=>node.onload?.());return result;};
|
||||
globalThis.innerWidth=1280;
|
||||
try {
|
||||
await native.prepareNativeMode('user','plans');native.nativeMode('user','plans');
|
||||
const common=[...document.querySelectorAll('[data-fuc-native]')].filter(n=>!n.href.includes('/page/shop.css'));
|
||||
const dark=document.getElementById('native-dark'),bridge=document.getElementById('native-bridge');moved.length=0;
|
||||
await native.prepareNativeMode('user','wallet');native.nativeMode('user','wallet');
|
||||
assert.ok(common.length>5);assert.ok(common.every(n=>n.isConnected&&n.media==='all'));
|
||||
assert.equal(document.getElementById('native-dark'),dark);assert.equal(document.getElementById('native-bridge'),bridge);
|
||||
assert.deepEqual(moved,[],'reparenting loaded LINKs can unload CSS and flash an unstyled page');
|
||||
const before=[...document.querySelectorAll('[data-fuc-native]')];
|
||||
const changing=native.prepareNativeMode('auth','login');assert.ok(before.every(n=>n.isConnected&&n.media==='all'));
|
||||
await changing;native.nativeMode('auth','login');
|
||||
assert.ok(before.every(n=>!n.isConnected));
|
||||
const styles=JSON.parse(await fs.readFile(new URL('../../theme/Fuc/assets/native/styles.json',import.meta.url),'utf8'));
|
||||
assert.deepEqual([...document.querySelectorAll('[data-fuc-native]')].map(n=>n.href.split('/native/')[1].split('?')[0]),styles.login.map(p=>p.split('?')[0]));
|
||||
assert.equal([...document.querySelectorAll('link[rel=stylesheet]')].at(-1),bridge,'overrides keep their position after the native CSS');
|
||||
}finally{document.head.append=append;document.head.insertBefore=insert;}
|
||||
});
|
||||
test('wallet-funded checkout and history show package value instead of zero online remainder',()=>{
|
||||
const order={trade_no:'synthetic-wallet-order',status:3,total_amount:0,balance_amount:10000,surplus_amount:0,surplus_credit:0,period:'month_price',plan:{name:'Synthetic plan'},created_at:1};
|
||||
const context={user:{},sub:{},data:order,methods:[],config:{}};
|
||||
|
||||
Reference in new issue
Block a user